IT-VBFK / dotnet-project-file-analyzers

Contains rolsyn static code analyzers to analyze .NET project files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

License: MIT Code of Conduct

.NET project file analyzers logo

.NET project file analyzers

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

Installation

Package NuGet
DotNetProjectFile.Analyzers DotNetProjectFile.AnalyzersDotNetProjectFile.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

Rules

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.

Additional files

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>

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

About

Contains rolsyn static code analyzers to analyze .NET project files.

License:MIT License


Languages

Language:C# 99.3%Language:PowerShell 0.5%Language:Visual Basic .NET 0.2%