All jobs

Add a dotnet format Check to a .NET CI Workflow

Yes. An agent runs dotnet format against your solution and .editorconfig, fixes what it finds in one commit, adds a verify step to CI and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the solution into its own cloud sandbox and reads the build inputs first. In a repository like jasontaylordev/CleanArchitecture, global.json pins SDK 10.0.403 with rollForward: latestFeature, Directory.Build.props sets net10.0, TreatWarningsAsErrors to true with NU1608 excepted, ImplicitUsings and Nullable on and an ArtifactsPath under artifacts/, and Directory.Packages.props turns on central package management with transitive pinning. The solution file is CleanArchitecture.slnx, with src/ holding Domain, Application, Infrastructure, Web, AppHost, ServiceDefaults and Shared, and tests/ six test projects. The agent installs the SDK that global.json names in the sandbox and runs dotnet restore once before anything else.

It then reads the .editorconfig, all 382 lines of it. The [*.cs] section sets four-space indentation, end_of_line = lf and insert_final_newline = true; [*.{cs,vb}] sets dotnet_sort_system_directives_first = true and csharp_new_line_before_open_brace = all, and most style rules below are written with a :silent severity, such as csharp_using_directive_placement = outside_namespace:silent and the csharp_style_var_* family. That severity matters: dotnet format style enforces only diagnostics at warning or above unless told otherwise, so with this file the enforceable check is whitespace plus using ordering and the handful of rules at :suggestion, and the agent says so rather than promising a style gate the config does not define.

Next it runs dotnet format CleanArchitecture.slnx --verify-no-changes --no-restore --verbosity diagnostic in the sandbox and reads the report. When the tree already conforms, the pull request is the CI step alone. When it does not, the agent runs dotnet format once, commits the whitespace and using-order changes as their own commit with no other edits, and then adds the verify step, so the review has one commit of mechanical reformatting and one of workflow change. It does not raise any :silent rule to a warning, because that is a team decision about style, and it lists the rules it would consider in the description.

The workflow change goes into .github/workflows/build.yml, which runs on pull requests to main, caches NuGet packages keyed on Directory.Packages.props and the project files, sets up Node.js 24 for the two client apps, restores, builds Release, installs Playwright browsers from artifacts/bin/Web.AcceptanceTests and runs dotnet test. The verify step lands after Restore solution and before Build solution, with --no-restore, so a formatting failure stops the job in seconds instead of after a full build. This repository is also a template: its workflows carry #if (!UseApiOnly) markers around the client steps, and the agent keeps the new step outside those markers so every generated solution gets it. test-templates.yml, which installs the template and generates solutions across a client and database matrix, is left as it is.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add a dotnet format check to this .NET repository's CI. Read global.json, Directory.Build.props, Directory.Packages.props, the .editorconfig and every workflow under .github/workflows first. Install the SDK global.json names, restore, and run dotnet format with --verify-no-changes against the solution file. If the tree does not conform, run dotnet format once and commit only the whitespace and using-order changes as a separate commit. Then add a verify step to the pull request workflow after restore and before build, using --no-restore. Do not change any rule severity in .editorconfig; list the rules at silent severity that the check will not enforce in the pull request description. Keep template conditional markers in the workflow intact. Open a pull request that includes the verify output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request with one or two commits. The workflow commit adds a single Verify formatting step to build.yml, and when the tree needed it, a preceding commit holds the mechanical reformatting with the dotnet format report quoted in the description so a reviewer can scroll past it with confidence. The .editorconfig is unchanged.

The run's record keeps the SDK install, the restore and both dotnet format invocations, the verify that found changes and the verify that passed after them, so the pull request's claim that the check is green at this commit is backed by the command output rather than by a sentence.

Before merging, a reviewer decides whether any of the :silent rules the description lists should become warnings in a follow-up, checks that the step sits in the job they expect to gate pull requests, and confirms the reformatting commit touches whitespace and usings only.

Run it on every pull request

With the step in CI, a pull request that fails it still needs a person to read the diagnostic log and apply the fix. An automation with a github trigger on pull_request.opened and pull_request.synchronize starts one run per pull request that checks out the branch, runs the same dotnet format --verify-no-changes the workflow runs, and when it passes ends with a one-line note. Only work by an owner, member or collaborator fires the trigger; pull requests from forks never do.

When it fails, the run posts one review that cites each file and the lines dotnet format would change, with the formatted version as a suggestion the author can apply from the pull request page. It pushes no commits to the author's branch; the author accepts the suggestions or runs dotnet format locally, and the next push starts a fresh run.

The use case this job follows, with its automation and trigger: Review every pull request.

Why run it on Rush?

A formatting check is cheap to add and easy to get wrong: the first run against an existing tree often fails on hundreds of files, and a pull request that mixes that reformatting with a workflow change is unreviewable. The agent does the expensive part in its own sandbox, a real SDK install, restore and format run against the real solution, and separates the mechanical commit from the one that matters, with the command output in the record so nobody has to re-run it to believe it.

For an organisation standardising on one .editorconfig, the same request goes to every .NET repository and returns one pull request each, built from that repository's own solution file and workflow rather than a copied snippet. Repositories that already conform come back with the step alone; the ones that do not come back with the reformatting isolated and counted.

Frequently asked questions

Will the check enforce the style rules in .editorconfig?

Only those at warning severity or above. Most of this file's style rules are written as :silent, so dotnet format --verify-no-changes enforces whitespace, final newlines, line endings and System using ordering, plus the few rules at :suggestion when --severity is lowered. The agent lists what is and is not enforced instead of changing severities for you.

Does it work with a .slnx solution file?

The agent passes the solution file the repository has, CleanArchitecture.slnx here, to dotnet format and to the verify step, under the SDK global.json pins. If the installed SDK did not accept the file, the run would show that error in its record and stop with needs_review rather than guess.

Why run the check before the build?

Formatting needs a restore but not a compile, so placing it after Restore solution with --no-restore fails fast. A pull request with a stray tab learns that in seconds instead of after a Release build, a Playwright install and the full test suite.

Will it reformat my whole codebase?

Only when the tree does not already pass, and then in its own commit that contains nothing else, with the report in the pull request. If you would rather land the workflow step first and reformat later, say so in the prompt and the agent opens the step alone and leaves the report as a comment.

More .NET jobs

More jobs like this: Review every pull request

Keep reading