Skip to main content

Installation

Stackworx.Analyzers is a collection of Roslyn analyzers that help enforce architectural patterns and best practices in your C# projects.

Quick Start

Via CLI

dotnet add package Stackworx.Analyzers

Via Project File

Add the package reference to your .csproj file:

<ItemGroup>
<PackageReference Include="Stackworx.Analyzers" Version="*" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
note

The OutputItemType="Analyzer" and ReferenceOutputAssembly="false" attributes ensure the package is used only for analysis and is not included as a runtime dependency.

Configuration

EditorConfig

Some analyzers require configuration through your .editorconfig file. At minimum, you may want to configure feature namespaces if using the namespace-related analyzers:

# .editorconfig
[*.cs]
dotnet_code_quality.Stackworx.Analyzers.feature_namespaces = MyCompany.Features

Replace MyCompany.Features with your actual feature namespace root.

Rule Configuration

You can enable, disable, or change the severity of individual rules. For example:

[*.cs]
# Disable a specific rule
dotnet_diagnostic.SW001.severity = none

# Change a rule to error
dotnet_diagnostic.SWGQL03.severity = error

# Change a rule to warning (default)
dotnet_diagnostic.SWGQL01.severity = warning

# Enable rules that are disabled by default
dotnet_diagnostic.SW002.severity = warning # Unused method (disabled by default — see SW002 docs for caveats)

Verification

After installation, build your project to verify the analyzers are working:

dotnet build

You should see warnings or errors from the analyzers in your build output, depending on your code and the default severity of each rule.

Next Steps

  • Review the Rules Overview to understand what each analyzer does
  • Check individual rule documentation for detailed information
  • Configure rules in your .editorconfig to match your project's requirements