Enable or install first-party .NET analyzers
.NET compiler platform (Roslyn) analyzers inspect your C# or Visual Basic code for code quality and code style issues. The first-party .NET analyzers are target-platform agnostic. That is, your project does not need to target a specific .NET platform. The analyzers work for projects that target
net5.0 as well as earlier .NET versions, such as
You can enable or install the first-party .NET analyzers in one of the following ways:
Enable from the .NET SDK: Starting in Visual Studio 2019 16.8 and .NET 5.0, these analyzers are included with the .NET SDK. Analysis is enabled, by default, for projects that target .NET 5.0 or later. You can enable code analysis on projects that target earlier .NET versions by setting the MSBUILD EnableNETAnalyzers property to
true. You can also disable code analysis for your project by setting
Install as a NuGet package: If you don't want to move to the .NET 5+ SDK or if you prefer a NuGet package-based model, the analyzers are also available in the
Microsoft.CodeAnalysis.NetAnalyzersNuGet package on Visual Studio 2019. You might prefer a package-based model for on-demand version updates. If you are on Visual Studio 2017, install the latest
2.9.xversion of the
Microsoft.CodeAnalysis.FxCopAnalyzersNuGet package instead.
It is recommended that you enable the analyzers from the .NET SDK instead of installing the
Microsoft.CodeAnalysis.NetAnalyzers NuGet package, when possible. Enabling the analyzers from the .NET SDK ensures that you automatically get the analyzer bug fixes and new analyzers as soon as you update the SDK. In the NuGet model, you need to update the NuGet package each time you want the latest bug fixes. The NuGet package is updated more frequently.