Search code examples
c#code-analysisroslyn-code-analysis

What's the difference between Microsoft.CodeAnalysis.FxCopAnalyzers and Microsoft.CodeAnalysis?


I want to install code analysis in one of my C# projects, and it seems that the way people add code analysis to .NET Core projects is by using the NuGet package Microsoft.CodeAnalysis.FxCopAnalyzers.

However, I also found other NuGet packages from the Microsoft.CodeAnalysis namespace, namely Microsoft.CodeAnalysis, Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.Features, etc.

What is the purpose of these other packages in comparison to the FxCopAnalyers package? The package descriptions are not very clear, so I don't know what their use cases are.

EDIT 2021: From current documentation: Prior to Visual Studio 2019 16.8 and .NET 5.0, code 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. Please consider migrating from FxCop analyzers to .NET analyzers.


Solution

  • Microsoft.CodeAnalysis.FxCopAnalyzers is just a set of analyzers which analyze your code as some other analyzers, IDEs, etc. This package analyzes your code for performance, design issues, and so on, and so forth.

    However, Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.VisualBasic, Microsoft.CodeAnalysis.Workspaces and other similar packages allow you to programmatically analyze input code, write custom static code analyzers and rulesets, investigate semantic and syntactical code models, and use some helpful logic to extend Visual Studio features, and so on, and so forth.