### Complete NsDepCop Project Configuration Example
Source: https://context7.com/realvizu/nsdepcop/llms.txt
A comprehensive XML configuration for NsDepCop, demonstrating multi-layer application setup with allowed and disallowed dependencies for both namespaces and assemblies.
```xml
```
--------------------------------
### Denylisting Configuration Example
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Use denylisting to allow most dependencies while prohibiting specific ones. Start by allowing all, then specify disallowed combinations.
```xml
```
--------------------------------
### Master Configuration File Example
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
This is an example of a master `config.nsdepcop` file located in a common ancestor folder (e.g., solution folder). It defines common allowed dependencies that can be inherited by child project configurations.
```xml
```
--------------------------------
### Install NsDepCop via .NET CLI
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Install the NsDepCop NuGet package using the .NET CLI. This command adds the package to your project.
```bash
# Install via .NET CLI
dotnet add package NsDepCop
```
--------------------------------
### Minimal Project-Level Config for Inheritance
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
A minimal `config.nsdepcop` file in a project folder is required to enable inheritance, even if all settings are inherited. This example sets `InheritanceDepth` to enable the inheritance mechanism.
```xml
```
--------------------------------
### Config Inheritance Example
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Configure inheritance to share rules across projects. A master config in the solution folder can be inherited by project-level configs.
```xml
```
--------------------------------
### Install NsDepCop via Package Manager Console
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Install the NsDepCop NuGet package using the Package Manager Console in Visual Studio. This command adds the package to your project.
```powershell
# Or via Package Manager Console
Install-Package NsDepCop
```
--------------------------------
### NsDepCop Namespace Dependency Rules with Wildcards
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Examples of defining namespace dependency rules using exact names, wildcards (*, ?), and regex patterns. These rules control which namespaces can reference others.
```xml
```
--------------------------------
### Namespace Dependency Example
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/DependencyControl.md
Illustrates a scenario where Namespace A depends on Namespace B through inheritance, field usage, properties, and method signatures.
```csharp
namespace A
{
using B;
class A1 : B1
{
B2 field1;
B3 Property1 { get; set; }
B4 MyMethod(B5 p) { ... }
}
}
namespace B
{
interface B1 {}
class B2 {}
struct B3 {}
enum B4 {}
delegate void B5();
}
```
--------------------------------
### Visible Members Configuration Example
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Control which types from a namespace are visible to others using VisibleMembers. This can be defined per-dependency or globally.
```xml
```
--------------------------------
### Disable NsDepCop with Environment Variable
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Globally disable the NsDepCop tool by setting the DisableNsDepCop environment variable to 'true' or '1'. This affects newly started processes, including MSBuild and Visual Studio integrations.
```bash
setx DisableNsDepCop 1
```
--------------------------------
### Run Unit Tests
Source: https://github.com/realvizu/nsdepcop/blob/master/CLAUDE.md
Executes the unit tests for the NsDepCop.Test project.
```bash
dotnet test source/NsDepCop.Test/NsDepCop.Test.csproj
```
--------------------------------
### Project-Level Configuration with Inheritance
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
This `config.nsdepcop` file in a project folder enables configuration inheritance by setting `InheritanceDepth`. It defines project-specific allowed dependencies that take precedence over inherited settings.
```xml
```
--------------------------------
### Build Analyzer Project
Source: https://github.com/realvizu/nsdepcop/blob/master/CLAUDE.md
Builds the analyzer project, which automatically restores and builds its dependencies.
```bash
dotnet build source/NsDepCop.Analyzer/NsDepCop.Analyzer.csproj
```
--------------------------------
### Basic NsDepCop Configuration
Source: https://context7.com/realvizu/nsdepcop/llms.txt
A basic configuration file for NsDepCop. Ensure the build action is set to 'C# analyzer additional file'. This configuration allows all namespaces to use System.* and the global namespace, and defines specific dependencies between layers of the application.
```xml
```
--------------------------------
### Run Source-Based Integration Tests
Source: https://github.com/realvizu/nsdepcop/blob/master/CLAUDE.md
Executes integration tests that verify the analyzer against C# source files.
```bash
dotnet test source/NsDepCop.SourceTest/NsDepCop.SourceTest.csproj
```
--------------------------------
### Default Assembly References for Allowlisting
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
When using an allowlisting approach for assemblies, include these rules to permit references to core .NET assemblies like mscorlib, netstandard, and System.*.
```xml
```
--------------------------------
### Configure Allowed Namespace Dependencies
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Defines which namespaces are allowed to reference others. Use this to enforce architectural boundaries. Supports wildcard and exact matching.
```xml
```
--------------------------------
### Run Single Test by Name
Source: https://github.com/realvizu/nsdepcop/blob/master/CLAUDE.md
Executes a specific test case by its fully qualified name.
```bash
dotnet test source/NsDepCop.Test/NsDepCop.Test.csproj --filter "FullyQualifiedName~TestMethodName"
```
--------------------------------
### Disable NsDepCop in Directory.Build.Props
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Create or update this file in the source root to prevent NsDepCop from running during every build.
```xml
true
```
--------------------------------
### NsDepCop Assembly Dependency Rules
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Configuration for enabling and defining assembly-level dependency rules. This checks which assemblies can reference other assemblies. Assembly dependency checking is disabled by default.
```xml
```
--------------------------------
### Configure Assembly Dependency Checking
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Enables assembly dependency checking and defines allowed and disallowed assembly references. Use 'CheckAssemblyDependencies="true"' to activate this feature.
```xml
```
--------------------------------
### Allow Namespace Dependency
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Defines that the 'From' namespace can depend on the 'To' namespace. Wildcards can be used for broader matching.
```xml
```
```xml
```
```xml
```
```xml
```
```xml
```
--------------------------------
### Set MaxIssueCount for Gradual Adoption
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Configure NsDepCop to allow a specific number of existing violations while preventing new ones. This setting automatically lowers the count as issues are fixed.
```xml
```
--------------------------------
### Disable NsDepCop in Directory.Build.props
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Disable NsDepCop for all projects within a directory tree by setting the `DisableNsDepCop` property in `Directory.Build.props`.
```xml
true
```
--------------------------------
### NsDepCopConfig Attributes Reference
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Configure analyzer behavior using attributes on the root NsDepCopConfig element. These attributes control various aspects of the analysis process.
```xml
```
--------------------------------
### Disable NsDepCop Globally via Environment Variable
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Use the `setx` command to disable NsDepCop globally for all projects by setting the `DisableNsDepCop` environment variable.
```bash
# Disable globally via environment variable
setx DisableNsDepCop 1
# Or set to true
setx DisableNsDepCop true
```
--------------------------------
### Deny Namespace Dependency
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Defines that the 'From' namespace must not depend on the 'To' namespace. This requires an 'allow all' rule to be present for denylisting to function.
```xml
```
--------------------------------
### Force NsDepCop execution in MSBuild
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Use this command to override the disabled state and force the tool to run during an MSBuild process.
```bash
msbuild MySolution.sln -t:NsDepCop_Analyze -p:ForceNsDepCop=true
```
--------------------------------
### NsDepCop Diagnostic Codes Reference
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Reference for NsDepCop diagnostic codes, including their severity and suggested fixes. These codes appear in the Visual Studio Error List and build output.
```text
NSDEPCOP01 - Illegal namespace reference
Severity: Warning (default)
The designated type cannot reference the other type because their
namespaces cannot depend on each other according to the current rules.
Fix: Update config.nsdepcop rules or refactor to avoid the dependency.
NSDEPCOP02 - Too many dependency issues
Severity: Warning (default)
The number of issues exceeded MaxIssueCount, analysis was stopped.
Fix: Correct reported issues or increase MaxIssueCount.
NSDEPCOP03 - No config file found
Severity: Info
No config.nsdepcop file was found with build action 'C# analyzer additional file'.
Fix: Add config.nsdepcop to the project if analysis is desired.
NSDEPCOP04 - Analysis disabled
Severity: Info
IsEnabled="false" was set in the config file.
NSDEPCOP05 - Config error
Severity: Error
Error loading config.nsdepcop (malformed XML, file permissions, etc.).
Fix: Verify config file syntax and accessibility.
NSDEPCOP06 - Tool disabled via environment variable
Severity: Info
The DisableNsDepCop environment variable is set to True or 1.
NSDEPCOP07 - Illegal assembly reference
Severity: Warning (default)
The designated assembly cannot reference another assembly per current rules.
Fix: Update assembly dependency rules or refactor project references.
```
--------------------------------
### Set Max Issue Count in NsDepCop Config
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Configure NsDepCop to prevent the introduction of new dependency issues by setting the current number of issues as the maximum allowed. This ensures that no new issues can be created until existing ones are resolved.
```xml
```
--------------------------------
### Enable Implicit Child-to-Parent Namespace Dependencies
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Set `ChildCanDependOnParentImplicitly` to 'true' on the `NsDepCopConfig` element to allow child namespaces to implicitly depend on their parent namespaces, similar to C# type resolution. The default is 'false' for backward compatibility.
```xml
```
--------------------------------
### Enable Auto Lower Max Issue Count in NsDepCop Config
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Enable automatic reduction of the maximum issue count to encourage gradual fixing of dependency issues. This setting helps developers address problems over time by progressively lowering the threshold.
```xml
```
--------------------------------
### Define Namespace Surface for Specific Dependency
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Use `` within an `` element to specify which types from a namespace are visible to another specific namespace. This controls the surface of a namespace for a particular dependency.
```xml
```
--------------------------------
### Define Global Namespace Surface
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Use `` with the `OfNamespace` attribute to define a global surface for a namespace, making specified types visible to all namespaces that depend on it. This is not embedded within an `` element.
```xml
```
--------------------------------
### Configure Analyzer Service Call Retry Time Spans
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Troubleshooting.md
Set longer wait intervals for the analyzer server to spin up by adding AnalyzerServiceCallRetryTimeSpans to your config.nsdepcop file. This is useful for older versions of NsDepCop.
```xml
```
--------------------------------
### Allow Referencing Global Namespace for Anonymous Types
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Troubleshooting.md
To avoid false alarms caused by anonymous types in older NsDepCop versions, add a rule to allow referencing the global namespace. This configuration is added to your config.nsdepcop file.
```xml
```
```xml
```
--------------------------------
### Disable NsDepCop with MSBuild Property
Source: https://github.com/realvizu/nsdepcop/blob/master/doc/Help.md
Disable the NsDepCop tool within MSBuild builds by setting the DisableNsDepCop property to 'true'. This is an alternative to using environment variables for disabling the tool during the build process.
```xml
true
```
--------------------------------
### Disable NsDepCop in Specific Config File
Source: https://context7.com/realvizu/nsdepcop/llms.txt
Disable NsDepCop for a specific project or configuration by setting `IsEnabled` to `false` within its `NsDepCopConfig` file.
```xml
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.