Use a repo-root `.editorconfig` to configure free .NET analyzer and style rules.
dotnet format
Format or verify trusted .NET projects with the SDK-provided `dotnet format` command. USE FOR: applying or checking `.editorconfig`-driven whitespace, code-style, or analyzer fixes; adding a `--verify-no-changes` CI gate; diagnosing formatter scope or load failures. DO NOT USE FOR: repositories where another formatter exclusively owns the affected files; analyzer policy with no formatter work; mutating files when the user requested only diagnosis.
Workflow
- Read the nearest
AGENTS.md,global.json, solution/project files,.editorconfig, and current Git status. - Confirm the exact trusted workspace to load.
dotnet formatmay restore, compile, and run analyzers from that workspace. - Determine whether the request is read-only verification or permission to apply fixes. Do not run a mutating command for a review, explanation, or diagnosis request.
- Preserve the current diff before formatting. When scope is uncertain, begin with
--verify-no-changesor a narrow--includelist. - Choose the smallest formatter surface that matches the request:
- whitespace for indentation, spacing, and line-ending rules; - style for built-in .NET code-style diagnostics; - analyzers for fixable non-style analyzer diagnostics; - the command without a subcommand only when all applicable surfaces are intended.
- Treat
--includeand--excludevalues as workspace-relative file or directory paths, not shell globs. Use--diagnosticsto narrow style or analyzer fixes by rule ID. - After a mutating run, inspect
git diff --stat, representative diffs, line endings, and every changed file. If scope is unexpectedly broad, stop and narrow the command; never discard pre-existing user changes. - Rerun the matching command with
--verify-no-changes. When analyzer fixes were applied, also build and run the tests relevant to the changed behavior.
References
- Read references/commands.md for precise local, CI, filtering, and troubleshooting commands.
- Read references/config.md when changing
.editorconfig, analyzer severity, or formatter ownership.
Related skills
Use the open-source free `CSharpier` formatter for C# and XML.
Use Chous in .NET repositories that ship sizeable frontend codebases and want file-structure linting, naming convention enforcement, and folder-layout policy as a CLI gate.