Contains 140+ Roslyn (static code) diagnostic analyzers that report issues on .NET project files.
The full documentation can be found here.
Packages | NuGet |
---|---|
DotNetProjectFile.Analyzers | |
DotNetProjectFile.Analyzers.Sdk |
To use the analyzers, you must include the analyzer NuGet package in your project file:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="DotNetProjectFile.Analyzers" Version="*" PrivateAssets="all" ExcudeAssets="runtime" />
</ItemGroup>
</Project>
or via PowerShell:
Install-Package DotNetProjectFile.Analyzers
The analyzer rules can be configured using the .globalconfig
file or by using <GlobalAnalyzerConfigFiles>
.
Instructions can be found here.
An example configuration with the default severities of the main branch of the analyzer can be found here.
To use the SDK, follow the instructions here.
To fully benefit from these analyzers it is recommended to add the project file (and RESX, and imported projects/props) as additional files.
To add a project file:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<AdditionalFiles Include="*.??proj" Visible="false" />
<AdditionalFiles Include="*.resx" />
</ItemGroup>
</Project>
To add a props file:
<Project>
<ItemGroup>
<AdditionalFiles Include="../props/{file_name}" Link="Properties/{file_name}" />
<AdditionalFiles Include="*.resx" />
</ItemGroup>
</Project>
For debugging/development purposes, it can be useful to reference the analyzer project directly. As mentioned here, this can be achieved by adding the following to your project file:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup Label="Analyzer">
<ProjectReference
Include="../../src/DotNetProjectFile.Analyzers/DotNetProjectFile.Analyzers.csproj"
PrivateAssets="all"
ReferenceOutputAssembly="false"
OutputItemType="Analyzer"
SetTargetFramework="TargetFramework=netstandard2.0" />
</ItemGroup>
</Project>