Condividi tramite


Migrate from FxCop analyzers to .NET analyzers

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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.

Note

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 netcoreapp, netstandard, and net472.

Migration steps

Starting with version 3.3.2, 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:

  1. Uninstall Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package

  2. Enable or install .NET analyzers. Note that you do not need to change your project's target platform.

  3. Enable additional rules: Microsoft.CodeAnalysis.NetAnalyzers is 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 AllEnabledByDefault will enable all the applicable CA rules as build warnings by default.

    <PropertyGroup>
      <AnalysisMode>AllEnabledByDefault</AnalysisMode>
    </PropertyGroup>
    

See also