Configure Code Analysis

VS Code

✅ Enable Roslyn Analyzer to highlight and fix code issues.

  1. Open VS Code. Go to ==File > Preferences > Settings== or press Ctrl+,.

  2. Go to Enable Roslyn Analyzers section and tick the checkbox to enable it.

Learn More:

ESLint your C# in VS Code with Roslyn Analyzers

✅ Install StyleCop to check coding style.

To format the source code in a project with StyleCop.Analyzers, you just need to add the StyleCop.Analyzers package to the project as follows. Once added, the dotnet format will seamlessly integrate with StyleCop.Analyzers.

dotnet add package Stylecop.Analyzers

Learn More:

The dotnet format command and StyleCop.Analyzers

✅ Auto-format code (whitespace & indentation).

You can use the following shortcuts to either format the entire document or specific-highlighted areas of your code;

  • Shift + Alt + F combination formats the entire document.
  • Ctrl + K, Ctrl + F combination formats a section of your code that you have selected.

Learn More:

How to Auto-Format in VS Code to Save Time and Effort [2023]