Skip to content

Dotnet format not applying rules specified in globalconfig #53750

@ellisbanan

Description

@ellisbanan

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

  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
    <PropertyGroup>
    <AnalysisMode>Recommended</AnalysisMode>
    <AnalysisLevel>10</AnalysisLevel>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    </PropertyGroup>
  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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions