format
GitHub利用 .NET SDK 内置的 dotnet format 工具,基于 .editorconfig 对代码进行格式化、风格检查或诊断。支持验证变更范围、应用样式/分析器修复,并集成 CI 门禁,确保代码规范一致性且不破坏现有逻辑。
Trigger Scenarios
Install
npx skills add managedcode/dotnet-skills --skill format -g -y
SKILL.md
Frontmatter
{
"name": "format",
"description": "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."
}
dotnet format
Use the formatter already shipped with the selected .NET SDK. Preserve the repository's formatter ownership, existing changes, and configured style instead of introducing new preferences.
Diagnostic Output Budget
Keep warnings/errors and a concise result; avoid routine verbose or diagnostic console output. Preserve native progress/ANSI when running tests. On failure, show only the relevant diagnostic and stack frames, deduplicated and capped at 80 lines / 8 KiB per response. Collect extra diagnostics only for an unresolved problem in size-bounded artifacts outside model context; link them and inspect exact bounded excerpts. Never dump full logs/reports or hide the command exit code through filtering.
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:
whitespacefor indentation, spacing, and line-ending rules;stylefor built-in .NET code-style diagnostics;analyzersfor 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.
Invariants
.editorconfigand existing MSBuild analyzer configuration are the source of truth. Do not add an arbitrary style template unless the user asks for one.- Use
--no-restoreonly after dependencies have already been restored successfully. - Generated files stay excluded unless the repository explicitly owns and formats them.
- A successful formatter process does not prove that every diagnostic has an automatic fix. Review its output or JSON report and use build/analyzer results as the final evidence.
- Keep formatter responsibilities explicit when CSharpier, ReSharper cleanup, generated-code tools, or other formatters coexist.
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.
Version History
-
bcd48ab
Current 2026-09-22 12:33
新增诊断输出预算控制规范,限制警告/错误行数与大小,避免冗长日志,确保故障排查时仅展示关键堆栈与诊断信息。
-
6cd8621
2026-09-03 08:02
重构技能结构,移除旧版 Ralph Loop 和 Bootstrap 逻辑,增强对 .editorconfig 和工作区范围的精确控制,明确只读与修改模式边界。
- 7ab7f03 2026-07-25 05:26


