Dotnet format not applying rules specified in globalconfig
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
**Summary**
I'm confused regarding the intended behavior of `dotnet format` and `dotnet build` when applying analyzer rules specified in analysislevel_X_recommended.globalconfig files. I have specifically tested with .Net8 and .Net10 with `analysismode = recommended` and the rules [CA2251](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2251) and [CA5374](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca5374). I noticed that these rules doesn't apply when using `dotnet format` but flag when apply `dotnet build`. In the globalconfig the severity is set to warning while the documentation either states hidden or not enabled by default depending on if you read documentation on dotnet/sdk repo or the microsoft page, respectively.
**Steps to reproduce**
1. Create new project with `dotnet new console`
2. Add rule exception (CA2251 Ex: `bool areEqualUsingCompare = string.CompareOrdinal("alpha", "ALPHA") == 0;`)
3. Specify Analysismode and level in csproj
``
`Recommended`
`10`
`true`
``
4. Run `dotnet format --verbosity detailed`
5. Run `dotnet build --verbosity detailed`
**Questions**
1. Should `dotnet format` apply analyzer settings specified in the `.globalconfig` folder or does it primarly rely on the `.editorconfig` file for configuration?
2. If it should adhere to globalconfig settings, why are rules like CA2251 and CA5374 not being applied by `dotnet format` when their severity is warning in the `.globalconfig`?
3. If not, how come `dotnet build` applies these rules if they are supposed to be disabled by default?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.