1(1) .NET (1)
2
3
4
6 This article applies to: ✔️ .NET 6.x SDK and later versions
7
9 dotnet format - Formats code to match editorconfig settings.
10
12 dotnet format [options] [<PROJECT | SOLUTION>]
13
14 dotnet format -h|--help
15
17 dotnet format is a code formatter that applies style preferences to a
18 project or solution. Preferences will be read from an .editorconfig
19 file, if present, otherwise a default set of preferences will be used.
20 For more information, see the EditorConfig documentation.
21
22 Arguments
23 PROJECT | SOLUTION
24
25 The MSBuild project or solution to run code formatting on. If a
26 project or solution file is not specified, MSBuild searches the current
27 working directory for a file that has a file extension that ends in
28 proj or sln, and uses that file.
29
31 None of the options below are required for the dotnet format command to
32 succeed but can be used to further customize what is formatted and by
33 which rules.
34
35 • --diagnostics <DIAGNOSTICS>
36
37 A space-separated list of diagnostic IDs to use as a filter when fix‐
38 ing code style or third party issues. Default value is whichever IDs
39 are listed in the editorconfig file. For a list of built-in analyzer
40 rule IDs that you can specify, see the list of IDs for code-analysis
41 quality rules.
42
43 • --severity
44
45 The minumum severity of diagnostics to fix. Allowed values are info,
46 warn, and error. The default value is warn
47
48 • --no-restore
49
50 Doesn’t execute an implicit restore before formatting. Default is to
51 do implicit restore.
52
53 • --verify-no-changes
54
55 Verifies that no formatting changes would be performed. Terminates
56 with a non zero exit code if any files would have been formatted.
57
58 • --include <INCLUDE>
59
60 A space-separated list of relative file or folder paths to include in
61 formatting. All files in the solution or project are formatted if
62 empty.
63
64 • --exclude <EXCLUDE>
65
66 A space-separated list of relative file or folder paths to exclude
67 from formatting. The default is none.
68
69 • --include-generated
70
71 Formats files generated by the SDK.
72
73 • -v|--verbosity <LEVEL>
74
75 Sets the verbosity level. Allowed values are q[uiet], m[inimal],
76 n[ormal], d[etailed], and diag[nostic]. Default value is m[inimal].
77
78 • --binarylog <BINARY-LOG-PATH>
79
80 Logs all project or solution load information to a binary log file.
81
82 • --report <REPORT-PATH>
83
84 Produces a JSON report in the directory specified by <REPORT_PATH>.
85
86 • -h|--help
87
88 Shows help and usage information
89
90 Subcommands
91 Whitespace
92 dotnet format whitespace - Formats code to match editorconfig settings
93 for whitespace.
94
96 The dotnet format whitespace subcommand will only run formatting rules
97 associated with whitespace formatting. For a complete list of possible
98 formatting options that you can specify in your .editorconfig file, see
99 the whitespace formatting documentation.
100
101 Style
102 dotnet format style - Formats code to match EditorConfig settings for
103 code style.
104
106 The dotnet format style subcommand will only run formatting rule asso‐
107 ciated with code style formatting. For a complete list of possible
108 formatting options that you can specify in your editorconfig file see
109 the code style documentation.
110
112 • --severity
113
114 The minimum severity of diagnostics to fix. Allowed values are info,
115 warn, and error. The default value is warn
116
117 Analyzers
118 dotnet format analyzers - Formats code to match editorconfig settings
119 for analyzers.
120
122 The dotnet format analyzers subcommand will only run formatting rule
123 associated with analyzers. For a list of possible analyzer rules that
124 you can specify in your editorconfig file see the list of ids for code-
125 analysis quality rules.
126
128 • --diagnostics <DIAGNOSTICS>
129
130 A space separated list of diagnostic ids to use as a filter when fix‐
131 ing code quality or 3rd party issues. Default value is whichever ids
132 are listed in the editorconfig file. For a list of built-in analyzer
133 rule ids that you can specify see the list of ids see the documenta‐
134 tion of code-analysis quality rules.
135
136 • --severity
137
138 The minimum severity of diagnostics to fix. Allowed values are info,
139 warn, and error. The default value is warn
140
142 • Format all code in the solution:
143
144 dotnet format ./solution.sln
145
146 • Clean up all code in the application project:
147
148 dotnet format ./src/application.csproj
149
150 • Verify that all code is correctly formatted:
151
152 dotnet format --verify-no-changes
153
154 • Clean up all code in the src and tests directory but not in src/sub‐
155 module-a:
156
157 dotnet format --include ./src/ ./tests/ --exclude ./src/submodule-a/
158
159
160
161 (1)