License: MIT Code of Conduct

.NET project file analyzers logo

.NET project file analyzers

Contains 130+ Roslyn (static code) diagnostic analyzers that report issues on .NET project files.

Documentation

The full documentation can be found here.

Installation

| Packages | NuGet | |————————————————————————————————–|————————————————————————————————————————————————————————————————————————————————————————–| |DotNetProjectFile.Analyzers | DotNetProjectFile.AnalyzersDotNetProjectFile.Analyzers | |DotNetProjectFile.Analyzers.Sdk| DotNetProjectFile.Analyzers.SdkDotNetProjectFile.Analyzers.Sdk |

Analyzers

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

Configuration

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.

SDK

To use the SDK, follow the instructions here.

Additional files

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>

Community

Reference an analyzer from a 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>