| name | add-analyzers |
| description | Use this skill to add essential code quality analyzers to .NET projects, including AsyncFixer, IDisposableAnalyzers, and Microsoft.VisualStudio.Threading.Analyzers with best-practice configurations. |
Add Code Analyzers
This guide will help you add essential code quality analyzers to your .NET project to enforce best practices for async programming, disposable patterns, and threading.
Overview
You'll be adding three powerful analyzers:
- AsyncFixer - Detects and fixes common async/await misuses
- IDisposableAnalyzers - Ensures proper disposal of resources
- Microsoft.VisualStudio.Threading.Analyzers - Enforces proper threading patterns
Step 1: Add Analyzer Packages
Add the following NuGet package references to your .csproj file(s):
<ItemGroup>
<PackageReference Include="AsyncFixer" Version="1.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
Where to Add
- For multiple projects: Add to each
.csproj file
Skip these project types — do NOT add analyzers to:
- Test projects (any
.csproj containing <IsTestProject>true</IsTestProject> or referencing xUnit/NUnit/MSTest)
*.Web.Host projects
*.Web.Core projects
Step 2: Configure Analyzer Rules
Replace or update your .editorconfig file in the backend folder with the following configuration:
[*.cs]
dotnet_diagnostic.IDISP001.severity = error
dotnet_diagnostic.IDISP002.severity = error
dotnet_diagnostic.IDISP003.severity = error
dotnet_diagnostic.IDISP004.severity = error
dotnet_diagnostic.IDISP005.severity = error
dotnet_diagnostic.IDISP006.severity = error
dotnet_diagnostic.IDISP007.severity = error
dotnet_diagnostic.IDISP008.severity = error
dotnet_diagnostic.IDISP009.severity = error
dotnet_diagnostic.IDISP010.severity = error
dotnet_diagnostic.IDISP011.severity = error
dotnet_diagnostic.IDISP012.severity = error
dotnet_diagnostic.IDISP013.severity = error
dotnet_diagnostic.IDISP014.severity = error
dotnet_diagnostic.IDISP015.severity = error
dotnet_diagnostic.IDISP016.severity = error
dotnet_diagnostic.IDISP017.severity = error
dotnet_diagnostic.IDISP018.severity = error
dotnet_diagnostic.IDISP019.severity = error
dotnet_diagnostic.IDISP020.severity = error
dotnet_diagnostic.IDISP021.severity = error
dotnet_diagnostic.IDISP022.severity = error
dotnet_diagnostic.IDISP023.severity = error
dotnet_diagnostic.IDISP024.severity = error
dotnet_diagnostic.IDISP025.severity = error
dotnet_diagnostic.IDISP026.severity = error
dotnet_diagnostic.VSTHRD001.severity = error
dotnet_diagnostic.VSTHRD002.severity = error
dotnet_diagnostic.VSTHRD003.severity = error
dotnet_diagnostic.VSTHRD004.severity = error
dotnet_diagnostic.VSTHRD010.severity = error
dotnet_diagnostic.VSTHRD011.severity = error
dotnet_diagnostic.VSTHRD012.severity = error
dotnet_diagnostic.VSTHRD100.severity = error
dotnet_diagnostic.VSTHRD101.severity = error
dotnet_diagnostic.VSTHRD102.severity = error
dotnet_diagnostic.VSTHRD103.severity = error
dotnet_diagnostic.VSTHRD104.severity = error
dotnet_diagnostic.VSTHRD105.severity = error
dotnet_diagnostic.VSTHRD106.severity = error
dotnet_diagnostic.VSTHRD107.severity = error
dotnet_diagnostic.VSTHRD108.severity = error
dotnet_diagnostic.VSTHRD109.severity = error
dotnet_diagnostic.VSTHRD110.severity = error
dotnet_diagnostic.VSTHRD111.severity = none
dotnet_diagnostic.VSTHRD112.severity = error
dotnet_diagnostic.VSTHRD113.severity = error
dotnet_diagnostic.VSTHRD114.severity = error
dotnet_diagnostic.VSTHRD115.severity = error
dotnet_diagnostic.VSTHRD200.severity = error
dotnet_diagnostic.AsyncFixer01.severity = none
dotnet_diagnostic.AsyncFixer04.severity = error
Step 3: Build and Review
After adding the analyzers:
-
Restore packages:
dotnet restore
-
Build your project:
dotnet build
-
Review warnings/errors:
- The analyzers will now flag violations in your code
- Fix critical errors first (disposal issues, async void, etc.)
- Address warnings based on priority