This article applies to: ✔️ .NET 6.x SDK and later versions
Contents
Arguments
PROJECT|SOLUTION
The MSBuild project or solution to run code formatting on. If a project or solution file is not speci‐
fied, MSBuild searches the current working directory for a file that has a file extension that ends in
proj or sln, and uses that file.
Description
The dotnetformatanalyzers subcommand only runs formatting rules associated with analyzers. For a list
of analyzer rules that you can specify in your editorconfig file, see Quality rules.
Dotnet Format
Thisarticleappliesto: ✔️ .NET 6.x SDK and later versions
Examples
• Format all code in the solution:
dotnet format ./solution.sln
• Clean up all code in the application project:
dotnet format ./src/application.csproj
• Verify that all code is correctly formatted:
dotnet format --verify-no-changes
• Clean up all code in the src and tests directory but not in src/submodule-a:
dotnet format --include ./src/ ./tests/ --exclude ./src/submodule-a/
• Fix a specific codestyle issue:
dotnet format style --diagnostics IDE0005 --severity info
• Fix all codestyle issues that have severity info, warning or error:
dotnet format style --severity info
• Fix a specific (non code style) analyzer issue:
dotnet format analyzers --diagnostics CA1831 --severity warn
• Fix all non code style issues that have severity info, warning or error:
dotnet format analyzers --severity info
2024-10-02 dotnet-format(1)
Name
dotnet-format - Formats code to match editorconfig settings.
Options
• --diagnostics<DIAGNOSTICS>
A space-separated list of diagnostic IDs to use as a filter when fixing non code style issues. Default
value is whichever IDs are listed in the .editorconfig file. For a list of built-in analyzer rule IDs
that you can specify, see the list of IDs for quality rules. For third-party analyzers refer to their
documentation.
• --severity
The minimum severity of diagnostics to fix. Allowed values are info, warn, and error. The default
value is warn.
Synopsis
dotnet format [<PROJECT | SOLUTION>] [command] [options]
dotnet format -h|--help
