Migrate from legacy analysis (FxCop) to source analysis (.NET analyzers)

Source analysis by .NET Compiler Platform ("Roslyn") analyzers replaces legacy analysis for managed code. For newer project templates such as .NET Core and .NET Standard projects, legacy analysis is not available.

Many of the legacy analysis (FxCop) rules have already been rewritten for .NET analyzers, a set of Roslyn code analyzers. Roslyn analyzers run source-code based analysis during compiler execution. Analyzer results are reported along with compiler results.

For more information on the differences between legacy analysis and source analysis, see the following:

Migration

To migrate to source analysis:

  1. Enable or install the .NET analyzers. Like legacy analysis rule violations, source code analysis violations appear in the Error List window in Visual Studio. In addition, source code analysis violations also show up in the code editor as squiggles under the offending code. The color of the squiggle depends on the severity setting of the rule. To see the status of rules ported to the new .NET analyzers, see Ported and unported rules.

    Note

    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. They are also available as Microsoft.CodeAnalysis.NetAnalyzers NuGet package. For more information, see Migrate from FxCop analyzers to .NET analyzers.

  2. To resolve CA0507, make sure that legacy code analysis is disabled for the project. In the project file, set the RunCodeAnalysis property to false:

    <RunCodeAnalysis>false</RunCodeAnalysis>

    Or, open Project Properties > Code Analysis and disable the Run on build setting.

Configuration

To learn more about how to configure the .NET analyzers: