The .NET Compiler Platform (Roslyn) can analyze your code for issues as you type using built-in or third-party analyzers. These analyzers are often called Roslyn Analyzers and are primarily used to help you write more maintainable code. Roslyn Analyzers can be configured by using either an EditorConfig file or a rule set file. Rules in the EditorConfig file override the rules the rule set file.
Scaffold uses both an EditorConfig file and a rule set file.
Starting in .NET 5, the .NET SDK includes analyzers for code styling and quality issues. They do not need to be install separately. Scaffold uses an EditorConfig file to configure these analyzers.
- Microsoft.CodeAnalysis.Diagnostics - Provides code style analysis.
- Microsoft.CodeAnalysis.NetAnalyzers - Provides code quality analysis.
Scaffold uses the following third-party Roslyn Analyzers in some or all of its projects. For an analyzer to work for a given project, it must be installed in that project. To install an analyzer globally for all projects, add the analyzer to Directory.Build.props. Scaffold uses a rule set file to configure these analyzers.
- IDisposableAnalyzers - Corrects the use of IDisposables.
- SonarAnalyzer.CSharp - Helps spot bugs and code smells.
- StyleCop.Analyzers - Enforce style and consistency when writing C# code.
- xUnit.Analyzers - Helps to write better tests.
Many analyzer issues can be quickly fixed by using the dotnet format
tool, which formats your code to match your EditorConfig file.
Scaffold uses the default EditorConfig file generated by the dotnet new editorconfig
command with the following settings appended.
# Scaffold - EditorConfig Overrides
# C# files
[*.cs]
# New line preferences
end_of_line = lf
insert_final_newline = true
# 'namespace' preferences
csharp_style_namespace_declarations = file_scoped:warning
# 'using' preferences
dotnet_diagnostic.IDE0005.severity = warning
dotnet_separate_import_directive_groups = false
csharp_using_directive_placement = inside_namespace:silent
# this. and Me. preferences
dotnet_style_qualification_for_event = true:silent
dotnet_style_qualification_for_field = true:silent
dotnet_style_qualification_for_method = true:silent
dotnet_style_qualification_for_property = true:silent
# Naming styles
dotnet_naming_style._camelcase.required_prefix =
# 'var' preferences
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_implicit_object_creation_when_type_is_apparent = false:warning
# Expression-bodied members
csharp_style_expression_bodied_lambdas = when_on_single_line
Code Style Rules - https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules
Code Quality Rules - https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules
Sonar Static Code Analysis Rules - https://rules.sonarsource.com/csharp
StyleCop.Analyzers Rules - https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/DOCUMENTATION.md
xUnit.Analyzers Rules - https://xunit.net/xunit.analyzers/rules