Contains Roslyn (static code) diagnostic analyzers that report issues on .NET project files.
Package | NuGet |
---|---|
DotNetProjectFile.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" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>
</Project>
or via PowerShell:
Install-Package DotNetProjectFile.Analyzers
There packaage contains rules about the MS Build project files (including imported props), and RESX files. The complete overview can be found at dotnet-project-file-analyzers.github.io.
To fully benefit from these analyzers it is recommended to add the project file (and imported projects/props) as additional files.
To add a project file:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<AdditionalFiles Include="*.??proj" Visible="false" />
</ItemGroup>
</Project>
To add a props file:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<AdditionalFiles Include="../props/{file_name}" Link="Properties/{file_name}" />
</ItemGroup>
</Project>
For debugging/development purposes, it can be useful to reference the analyzer project directly. Within this solution, that would look like:
<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>
See also: www.meziantou.net