dotnet "format --verify-no-changes" Fails in CI
A CI gate runs dotnet format --verify-no-changes to assert the code is already formatted. When the formatter would make changes, the command exits non-zero and fails the job - the code is not formatted to the project’s rules.
What this error means
The format-check step fails listing files and the formatting/style edits it would apply. Running dotnet format locally and committing makes it pass, confirming the code had drifted from the configured style.
Formatted code file 'Services/Cache.cs'.
error WHITESPACE: Fix whitespace formatting. Replace 6 characters with '\n '.
dotnet format --verify-no-changes exited with code 2.Common causes
Code not formatted to the project rules
Whitespace, ordering, or code-style rules in .editorconfig were not applied before commit, so the verify run detects pending changes.
Editor or contributor formatting differs
A contributor’s editor did not honor .editorconfig, producing formatting the project formatter would rewrite.
How to fix it
Run dotnet format and commit
Apply the formatter locally, then commit the result so the verify step passes.
dotnet format
git add -A && git commit -m "Apply dotnet format"Keep the verify gate in CI
Run the verify step so unformatted code fails fast in PRs.
- run: dotnet format --verify-no-changes --verbosity diagnosticHow to prevent it
- Run
dotnet format(or an editor that honors.editorconfig) before committing. - Commit a shared
.editorconfigso everyone formats identically. - Add a pre-commit hook that runs
dotnet formaton staged files.