9

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.

Andrej Lucansky
  • 725
  • 10
  • 17

1 Answers1

7

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.

bubbleking
  • 3,329
  • 3
  • 29
  • 49
George Alexandria
  • 2,841
  • 2
  • 16
  • 24
  • Does `Microsoft.CodeAnalysis` include all of them? – wltheng May 12 '20 at 13:08
  • @wltheng, No, it doesn't. Currently this package includes only the main packages for syntax/semantic and workspace analyzing: `Microsoft.CodeAnalysis.Compilers; Microsoft.CodeAnalysis.CSharp; Microsoft.CodeAnalysis.VisualBasic; Microsoft.CodeAnalysis.CSharp.Workspaces; Microsoft.CodeAnalysis.VisualBasic.Workspaces;` – George Alexandria May 12 '20 at 17:01
  • You must have Microsoft.CodeAnalysis.CSharp for analyzing csharp sources and working with compilations. – George Alexandria Apr 14 '21 at 18:45