Migrate from FxCop analyzers to .NET analyzers
Applies to: Visual Studio Visual Studio for Mac
Source analysis by .NET Compiler Platform ("Roslyn") analyzers replaces legacy analysis for managed code. Many of the legacy analysis (FxCop) rules have already been rewritten as source analyzers.
Prior to Visual Studio 2019 16.8 and .NET 5.0, these analyzers shipped as
Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package.
Starting in Visual Studio 2019 16.8 and .NET 5.0, these analyzers are included with the .NET SDK. 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.NetAnalyzers NuGet package. You might prefer a package-based model for on-demand version updates.
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
Starting with version
Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package has been deprecated. Please follow the below steps to migrate your project or solution from
Microsoft.CodeAnalysis.FxCopAnalyzers to the .NET analyzers:
Enable or install .NET analyzers. Note that you do not need to change your project's target platform.
Enable additional rules:
Microsoft.CodeAnalysis.NetAnalyzersis much more conservative compared to
Microsoft.CodeAnalysis.FxCopAnalyzers. Unlike FxCopAnalyzers package, it only has a few correctness rules which are enabled by default as build warnings. You can enable additional rules by customizing the AnalysisMode MSBuild property. For example, setting the property to
AllEnabledByDefaultwill enable all the applicable CA rules as build warnings by default.
<PropertyGroup> <AnalysisMode>AllEnabledByDefault</AnalysisMode> </PropertyGroup>
Submit and view feedback for