Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions plugins/dotnet/skills/dotnet-format/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
name: dotnet-format
description: >
Format C#/.NET source files using the `dotnet format whitespace` subcommand.
USE FOR: quickly fixing whitespace and indentation in one or more files after
code generation or editing, batch-formatting changed files before a commit.
DO NOT USE FOR: enforcing code-style analyzers (SA/IDE rules), fixing
non-whitespace style issues, or formatting entire large repositories at once.
---
Comment on lines +1 to +9

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skill adds a new plugins/dotnet/skills/dotnet-format entry, but the dotnet plugin README’s skill list doesn’t include dotnet-format (it currently lists only csharp-scripts, dotnet-pinvoke, and nuget-trusted-publishing). Please update plugins/dotnet/README.md to keep the published skill inventory accurate.

This issue also appears on line 15 of the same file.

Copilot uses AI. Check for mistakes.

# dotnet format (whitespace)

`dotnet format whitespace` reformats indentation, trailing whitespace, and line endings in C#/VB files without applying analyzer or code-style fixes. When used with `--folder`, it is the fastest `dotnet format` sub-command because in that mode it operates on syntax only and does not need to load the full MSBuild workspace; when run against a project or solution it still loads the workspace. It is also the safest because it never changes semantics.

## When to Use

- Fixing indentation or trailing whitespace in files you just created or edited
- Batch-formatting a set of changed files before committing
- Cleaning up generated code that has inconsistent whitespace

## When Not to Use

- You need code-style fixes (naming, `var` vs explicit type, etc.) — use `dotnet format style` instead
- You need analyzer-driven fixes (e.g., SA1200) — use `dotnet format analyzers` instead

## Workflow

### Step 1: Determine files to format

Identify the file paths that need formatting — typically files that were just created or edited.

### Step 2: Run `dotnet format whitespace`

Use `--folder` mode to format without needing a project/solution file:

```bash
# Format everything under the current directory
dotnet format whitespace --folder .

# Format only specific files
dotnet format whitespace --folder . --include path/to/File1.cs --include path/to/File2.cs
```

Key flags:

Always use `--folder` — without it, the tool loads the full MSBuild workspace which is much slower and unnecessary for whitespace-only formatting.

| Flag | Purpose |
|------|---------|
| `--folder` | Treats the argument as a plain directory — avoids loading the full workspace |
| `--include <path>` | Restricts formatting to the specified file(s); repeat for multiple files. Optional — omit to format all files in the folder |
| `--verify-no-changes` | Exits non-zero if any file would change (useful for CI checks) |
Comment thread
jjonescz marked this conversation as resolved.

Multiple files example:

```bash
dotnet format whitespace --folder . \
--include src/Models/User.cs \
--include src/Services/AuthService.cs \
--include tests/AuthTests.cs
```

### Step 3: Verify the result

Review the formatted files to confirm only whitespace changed. If you need to verify programmatically:

```bash
dotnet format whitespace --folder . --include path/to/File.cs --verify-no-changes
```

A zero exit code means the file is already correctly formatted.

## Validation

- [ ] `dotnet format whitespace` exits with code 0
- [ ] Only whitespace/indentation changed — no semantic modifications
- [ ] Formatted files still compile successfully

## Common Pitfalls

| Pitfall | Solution |
|---------|----------|
| Running without `--folder` | Loads the full MSBuild workspace, which is slow and unnecessary for whitespace formatting. Always use `--folder .` |
Comment thread
jjonescz marked this conversation as resolved.
| Formatting the entire repo unintentionally | Pass `--include` with specific file paths when you only want to format a subset |
| `.editorconfig` not found | `dotnet format` inherits `.editorconfig` settings; ensure one exists in a parent directory for consistent results |
37 changes: 37 additions & 0 deletions tests/dotnet/dotnet-format/eval.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
scenarios:
- name: "Format specific files after editing"
prompt: |
I just refactored two C# files and the indentation is all messed up:
- src/Services/OrderService.cs
- src/Models/Order.cs

I don't have a solution file in the current directory. Can you fix the whitespace formatting?
assertions:
- type: "output_contains"
value: "dotnet format whitespace"
- type: "output_contains"
value: "--folder"
- type: "output_matches"
pattern: "--include"
rubric:
Comment on lines +9 to +16

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenario 1’s assertions only check that the output mentions --include, but they don’t ensure the agent targets the specific files listed in the prompt. As written, the test can pass even if the agent formats the whole folder or includes unrelated paths. Consider asserting that the output contains both src/Services/OrderService.cs and src/Models/Order.cs (or a regex that requires both --include occurrences).

This issue also appears on line 28 of the same file.

Copilot uses AI. Check for mistakes.
- "Uses `dotnet format whitespace` specifically, not `dotnet format` without a subcommand or `dotnet format style`"
- "Uses --folder mode to avoid loading the MSBuild workspace"
- "Uses --include to target the specific files rather than formatting the entire directory"
timeout: 120

- name: "Verify whitespace formatting without modifying files"
prompt: |
I just ran `dotnet format whitespace` on some files in my repo but I want to
double-check that `src/Services/PaymentService.cs` is now correctly formatted.
Can you verify the formatting without modifying the file? I don't have a .sln
file in this directory.
assertions:
- type: "output_contains"
value: "dotnet format whitespace"
- type: "output_contains"
value: "--verify-no-changes"
rubric:
- "Uses `dotnet format whitespace` with `--verify-no-changes` to verify without modifying the file"
- "Uses --folder mode since there is no solution file available"
- "Uses --include to target the specific file rather than checking the entire directory"
timeout: 120
Loading