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 and 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
- Create new project with
dotnet new console
- Add rule exception (CA2251 Ex:
bool areEqualUsingCompare = string.CompareOrdinal("alpha", "ALPHA") == 0;)
- Specify Analysismode and level in csproj
<PropertyGroup>
<AnalysisMode>Recommended</AnalysisMode>
<AnalysisLevel>10</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
- Run
dotnet format --verbosity detailed
- Run
dotnet build --verbosity detailed
Questions
- Should
dotnet format apply analyzer settings specified in the .globalconfig folder or does it primarly rely on the .editorconfig file for configuration?
- 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?
- If not, how come
dotnet build applies these rules if they are supposed to be disabled by default?
Summary
I'm confused regarding the intended behavior of
dotnet formatanddotnet buildwhen applying analyzer rules specified in analysislevel_X_recommended.globalconfig files. I have specifically tested with .Net8 and .Net10 withanalysismode = recommendedand the rules CA2251 and CA5374. I noticed that these rules doesn't apply when usingdotnet formatbut flag when applydotnet 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
dotnet new consolebool areEqualUsingCompare = string.CompareOrdinal("alpha", "ALPHA") == 0;)<PropertyGroup><AnalysisMode>Recommended</AnalysisMode><AnalysisLevel>10</AnalysisLevel><TreatWarningsAsErrors>true</TreatWarningsAsErrors></PropertyGroup>dotnet format --verbosity detaileddotnet build --verbosity detailedQuestions
dotnet formatapply analyzer settings specified in the.globalconfigfolder or does it primarly rely on the.editorconfigfile for configuration?dotnet formatwhen their severity is warning in the.globalconfig?dotnet buildapplies these rules if they are supposed to be disabled by default?