=================================================================
The .NET compiler platform, also known as Roslyn, provides a set of analyzers that inspect your C# or Visual Basic code for style, quality, maintainability, design, and other issues. These analyzers are integrated into Visual Studio and can be configured to provide real-time feedback on your code.
There are several types of analyzers available, including:
Each Roslyn analyzer rule has a default severity and suppression state that can be customized for your project. The severity levels include:
For more information on configuring severity levels, see Configure severity levels.
If an analyzer finds any rule violations, it reports them in the Error List window and in the code editor. The analyzer violations are displayed as squiggle lines under the offending code, with different colors indicating the severity of the issue.
Many diagnostics have one or more associated code fixes that can be applied to correct the rule violation. Code fixes are shown in the light bulb icon menu along with other types of Quick Actions.
You can configure the severity of analyzer rules in an EditorConfig file or from the light bulb menu.
Visual Studio includes a core set of Roslyn analyzers, but you can install external analyzers for every project via a NuGet package. Some analyzers are also available as a Visual Studio .vsix extension, which applies to any solution you open in Visual Studio. For more information on installing external analyzers, see Install code analyzers.
If you install an analyzer as a NuGet package, it applies only to the project where the NuGet package is installed. If you install an analyzer as a Visual Studio extension, it applies at the solution level and to all instances of Visual Studio.
To enforce the rules at build time, you can create a .NET 5.0 or later project, which enables code analysis by default. Alternatively, you can install the analyzers as a NuGet package and set the EnableNETAnalyzers property to true.
For more information on using Roslyn analyzers, see: