1dotnet-format(1) .NET Documentation dotnet-format(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
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 you can use them to further customize what is formatted
33 and by 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 analyz‐
40 er rule IDs that you can specify, see the list of IDs for code-analy‐
41 sis style rules.
42
43 • --severity
44
45 The minimum 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. The default is all files in the solution or project.
62
63 • --exclude <EXCLUDE>
64
65 A space-separated list of relative file or folder paths to exclude
66 from formatting. The default is none.
67
68 • --include-generated
69
70 Formats files generated by the SDK.
71
72 • -v|--verbosity <LEVEL>
73
74 Sets the verbosity level. Allowed values are q[uiet], m[inimal],
75 n[ormal], d[etailed], and diag[nostic]. Default value is m[inimal].
76
77 • --binarylog <BINARY-LOG-PATH>
78
79 Logs all project or solution load information to a binary log file.
80
81 • --report <REPORT-PATH>
82
83 Produces a JSON report in the directory specified by <REPORT_PATH>.
84
85 • -h|--help
86
87 Shows help and usage information
88
89 Subcommands
90 Whitespace
91 dotnet format whitespace - Formats code to match editorconfig settings
92 for whitespace.
93
95 The dotnet format whitespace subcommand will only run formatting rules
96 associated with whitespace formatting. For a complete list of possible
97 formatting options that you can specify in your .editorconfig file, see
98 the C# formatting options.
99
101 • --folder
102
103 Treat the <PROJECT | SOLUTION> argument as a path to a simple folder
104 of code files.
105
106 Style
107 dotnet format style - Formats code to match EditorConfig settings for
108 code style.
109
111 The dotnet format style subcommand will only run formatting rule asso‐
112 ciated with code style formatting. For a complete list of formatting
113 options that you can specify in your editorconfig file, see Code style
114 rules.
115
117 • --diagnostics <DIAGNOSTICS>
118
119 A space-separated list of diagnostic IDs to use as a filter when fix‐
120 ing code style or third-party issues. Default value is whichever IDs
121 are listed in the .editorconfig file. For a list of built-in analyz‐
122 er rule IDs that you can specify, see the list of IDs for code-analy‐
123 sis style rules.
124
125 • --severity
126
127 The minimum severity of diagnostics to fix. Allowed values are info,
128 warn, and error. The default value is warn
129
130 Analyzers
131 dotnet format analyzers - Formats code to match editorconfig settings
132 for analyzers.
133
135 The dotnet format analyzers subcommand will only run formatting rule
136 associated with analyzers. For a list of analyzer rules that you can
137 specify in your editorconfig file, see Code style rules.
138
140 • --diagnostics <DIAGNOSTICS>
141
142 A space-separated list of diagnostic IDs to use as a filter when fix‐
143 ing code style or third-party issues. Default value is whichever IDs
144 are listed in the .editorconfig file. For a list of built-in analyz‐
145 er rule IDs that you can specify, see the list of IDs for code-analy‐
146 sis style rules.
147
148 • --severity
149
150 The minimum severity of diagnostics to fix. Allowed values are info,
151 warn, and error. The default value is warn.
152
154 • Format all code in the solution:
155
156 dotnet format ./solution.sln
157
158 • Clean up all code in the application project:
159
160 dotnet format ./src/application.csproj
161
162 • Verify that all code is correctly formatted:
163
164 dotnet format --verify-no-changes
165
166 • Clean up all code in the src and tests directory but not in src/sub‐
167 module-a:
168
169 dotnet format --include ./src/ ./tests/ --exclude ./src/submodule-a/
170
171
172
173 2022-06-20 dotnet-format(1)