Skip to content

Dotnet format not applying rules specified in globalconfig #53750

Open

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?

Activity

  1. added
    untriaged
    on Apr 8, 2026
  2. rjgotten commented on Oct 1, 2026

    @rjgotten

    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?

    It's seeing them at the rules' default analysis level, rather than at the level the globalconfig configures them.
    For many that will be info rather than warning. Which means you need to specifically run dotnet format --severity info.

    This smells like a nasty bug.
    In particular it makes dotnet format --verify-no-changes a quality gate that cannot be trusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Formatuntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions