coding-conventions/.NET/README.md

41 lines
2.7 KiB
Markdown
Raw Normal View History

2026-03-22 12:45:42 +01:00
# .NET
2026-03-22 12:53:07 +01:00
These are the configuration files for .NET projects or solutions.
2026-03-22 12:45:42 +01:00
You can copy these files into the root of your .NET solution in order to activate the conventions.
### directory.build.props
2026-03-22 12:53:07 +01:00
The `directory.build.props` contains important project configuration, that need to be set for all .NET projects in your solution. It will set some global compiler configuration and the static analyzers get imported via NuGet.
2026-03-22 12:45:42 +01:00
### .editorconfig
2026-03-22 12:53:07 +01:00
The `.editorconfig` contains configuration for your code editor and the ruleset of the static analyzers. Copy this file into the root of you repository so that it is active for all files and folders.
2026-03-22 12:45:42 +01:00
#### Analyzers
| Name | Version | NuGet |
|--------------------------------------------|----------------|--------------------------------------------------------------------------------------------|
| Microsoft.CodeAnalysis.NetAnalyzers | 8.0.0 | [NuGet](https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers/8.0.0) |
| Microsoft.VisualStudio.Threading.Analyzers | 17.8.14 | [NuGet](https://www.nuget.org/packages/Microsoft.VisualStudio.Threading.Analyzers/17.8.14) |
| Roslynator.Analyzers | 4.6.2 | [NuGet](https://www.nuget.org/packages/Roslynator.Analyzers/4.6.2) |
| Roslynator.CodeAnalysis.Analyzers | 4.6.2 | [NuGet](https://www.nuget.org/packages/Roslynator.CodeAnalysis.Analyzers/4.6.2) |
| Roslynator.Formatting.Analyzers | 4.6.2 | [NuGet](https://www.nuget.org/packages/Roslynator.Formatting.Analyzers/4.6.2) |
| StyleCop.Analyzers | 1.2.0-beta.556 | [NuGet](https://www.nuget.org/packages/StyleCop.Analyzers/1.2.0-beta.556) |
#### Priority
2026-03-22 12:53:07 +01:00
The analyzers are handled with priority. That means, that a violation of a rule from an analyzer with a higher priority overrides a violation of a lower priority analyzer. In case of conflicting rules from different analyzers, the rule from the analyzer with the lower priority gets changed or deactivated.
2026-03-22 12:45:42 +01:00
Priority of analyzers:
1. Microsoft.CodeAnalysis.NetAnalyzers
2. Microsoft.VisualStudio.Threading.Analyzers
3. StyleCop.Analyzers
4. Roslynator.Analyzers
5. Roslynator.CodeAnalysis.Analyzers
6. Roslynator.Formatting.Analyzers
### stylecop.json
2026-03-22 12:53:07 +01:00
The `stylecop.json` contains the configuration for "StyleCop.Analyzers", that cannot be set via the `.editorconfig`. This file must be copied into the root of your repository as it gets imported from there into all .NET projects by the `directory.build.props`.