title | description | ms.date |
---|---|---|
dotnet format command |
The dotnet format command formats code to match EditorConfig settings for the current directory. |
07/12/2021 |
This article applies to: ✔️ .NET 6.x SDK and later versions
dotnet format
- Formats code to match editorconfig
settings.
dotnet format [<PROJECT | SOLUTION>] [command] [options]
dotnet format -h|--help
dotnet format
is a code formatter that applies style preferences and static analysis recommendations to a project or solution. Preferences will be read from an .editorconfig file, if present, otherwise a default set of preferences will be used. For more information, see the EditorConfig documentation.
PROJECT | SOLUTION
The MSBuild project or solution to run code formatting on. If a project or solution file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in proj or sln, and uses that file.
None of the options below are required for the dotnet format
command to succeed, but you can use them to further customize what is formatted and by which rules.
-
--diagnostics <DIAGNOSTICS>
A space-separated list of diagnostic IDs to use as a filter when fixing code style or third-party 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 code-analysis style rules.
-
--severity
The minimum severity of diagnostics to fix. Allowed values are
info
,warn
, anderror
. The default value iswarn
. -
--no-restore
Doesn't execute an implicit restore before formatting. Default is to do implicit restore.
-
--verify-no-changes
Verifies that no formatting changes would be performed. Terminates with a non zero exit code if any files would have been formatted.
-
--include <INCLUDE>
A space-separated list of relative file or folder paths to include in formatting. The default is all files in the solution or project.
-
--exclude <EXCLUDE>
A space-separated list of relative file or folder paths to exclude from formatting. The default is none.
-
--include-generated
Formats files generated by the SDK.
-
-v|--verbosity <LEVEL>
Sets the verbosity level. Allowed values are
q[uiet]
,m[inimal]
,n[ormal]
,d[etailed]
, anddiag[nostic]
. Default value ism[inimal]
. -
--binarylog <BINARY-LOG-PATH>
Logs all project or solution load information to a binary log file.
-
--report <REPORT-PATH>
Produces a JSON report in the directory specified by
<REPORT_PATH>
. -
-h|--help
Shows help and usage information
dotnet format whitespace
- Formats code to match editorconfig
settings for whitespace.
The dotnet format whitespace
subcommand only runs formatting rules associated with whitespace formatting. For a complete list of possible formatting options that you can specify in your .editorconfig file, see the C# formatting options.
-
--folder
Treat the
<PROJECT | SOLUTION>
argument as a path to a simple folder of code files.
dotnet format style
- Formats code to match EditorConfig settings for code style.
The dotnet format style
subcommand only runs formatting rules associated with code style formatting. For a complete list of formatting options that you can specify in your editorconfig
file, see Code style rules.
-
--diagnostics <DIAGNOSTICS>
A space-separated list of diagnostic IDs to use as a filter when fixing code style or third-party 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 code-analysis style rules.
-
--severity
The minimum severity of diagnostics to fix. Allowed values are
info
,warn
, anderror
. The default value iswarn
dotnet format analyzers
- Formats code to match editorconfig
settings for analyzers.
The dotnet format analyzers
subcommand only runs formatting rules associated with analyzers. For a list of analyzer rules that you can specify in your editorconfig
file, see Code style rules.
-
--diagnostics <DIAGNOSTICS>
A space-separated list of diagnostic IDs to use as a filter when fixing code style or third-party 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 code-analysis style rules.
-
--severity
The minimum severity of diagnostics to fix. Allowed values are
info
,warn
, anderror
. The default value iswarn
.
-
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/