A curated set of code analyzers and code analyzer settings.
$ dotnet add package Microsoft.Extensions.StaticAnalysisA curated set of code analyzers and code analyzer settings.
From the command-line:
dotnet add package Microsoft.Extensions.StaticAnalysis
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.StaticAnalysis" Version="[CURRENTVERSION]" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
On install, a warning will be displayed that The StaticAnalysisCodeType property is not defined, assuming 'General'. The General set of diagnostics is enabled by default. To select a different set of diagnostics (or hide the warning) add the StaticAnalysisCodeType property to your project as follows.
<PropertyGroup>
<StaticAnalysisCodeType>General</StaticAnalysisCodeType>
</PropertyGroup>
Different pre-defined sets of diagnostics are available depending on the type of project being built. These can be specified in the StaticAnalysisCodeType property:
Each of these also has an optional -Tier1 and a -Tier2 variant (e.g. General-Tier1).
Tier1 enables only the most important diagnostics from this set.Tier2 includes Tier1 diagnostics and others that aren't as critical.Tier suffixes include all diagnostics from tier's 1 and 2, and any others that are applicable.We welcome feedback and contributions in our GitHub repo.