Roslyn analyzers

Visual Studio includes a built-in set of .NET Compiler Platform analyzers that analyze your C# or Visual Basic code as you type. Analyzers look at code style, code quality and maintainability, code design, and other issues. You can install additional analyzers as a Visual Studio extension, or on a per-project basis as a NuGet package.

If rule violations are found by an analyzer, they are reported both in the code editor as a squiggly under the offending code, and in the Error List. The color of the squiggly depends on the severity setting of the rule. Refer to Rule Severity.

The FxCop analyzer NuGet package includes predefined rule sets for the following rule categories:

  • design
  • documentation
  • maintainability
  • naming
  • performance
  • reliability
  • security
  • usage

Roslyn analyzers analyze code at build time, like static code analysis if it's enabled, but also live as you type! Roslyn analyzers can also provide design-time analysis of code files that aren't open in the editor if you enable full solution analysis.

Not only do Roslyn analyzers report the same types of problems that static code analysis does, but they make it easy for you to fix one, or all, occurrences of the violation in your file or project. These actions are called code fixes. Code fixes are IDE-specific; in Visual Studio, they are implemented as Quick Actions. Not all analyzer diagnostics have an associated code fix.

Many analyzer rules, or diagnostics, have one or more associated code fixes that you can apply to correct the problem. The analyzer diagnostics that are built into Visual Studio each have an associated code fix. Code fixes are shown in the light bulb icon menu, along with other types of Quick Actions