Provided by: dotnet-host-8.0_8.0.18-0ubuntu1~24.04.1_amd64 bug

dotnet format

       This article applies to: ✔️ .NET 6.x SDK and later versions

NAME

       dotnet-format - Formats code to match editorconfig settings.

SYNOPSIS

              dotnet format [options] [<PROJECT | SOLUTION>]

              dotnet format -h|--help

DESCRIPTION

       dotnet  format  is a code formatter that applies style preferences 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.

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.

OPTIONS

       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 is‐
         sues.  Default value is whichever IDs are listed in the .editorconfig file.  For a list of built-in an‐
         alyzer 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,  and  error.   The  default
         value is warn.

       • --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],  and  diag[nos‐
         tic].  Default value is m[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

   Subcommands
   Whitespace
       dotnet format whitespace - Formats code to match editorconfig settings for whitespace.

DESCRIPTION

       The dotnet format whitespace subcommand will only run formatting rules associated with whitespace format‐
       ting.   For  a  complete  list  of possible formatting options that you can specify in your .editorconfig
       file, see the C# formatting options.

OPTIONS

--folder

         Treat the <PROJECT | SOLUTION> argument as a path to a simple folder of code files.

   Style
       dotnet format style - Formats code to match EditorConfig settings for code style.

DESCRIPTION

       The dotnet format style subcommand will only run formatting rule associated with code  style  formatting.
       For  a complete list of formatting options that you can specify in your editorconfig file, see Code style
       rules.

OPTIONS

--diagnostics <DIAGNOSTICS>

         A space-separated list of diagnostic IDs to use as a filter when fixing code style or  third-party  is‐
         sues.  Default value is whichever IDs are listed in the .editorconfig file.  For a list of built-in an‐
         alyzer 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, and error.  The default
         value is warn

   Analyzers
       dotnet format analyzers - Formats code to match editorconfig settings for analyzers.

DESCRIPTION

       The dotnet format analyzers subcommand will only run formatting rule associated with  analyzers.   For  a
       list of analyzer rules that you can specify in your editorconfig file, see Code style rules.

OPTIONS

--diagnostics <DIAGNOSTICS>

         A  space-separated  list of diagnostic IDs to use as a filter when fixing code style or third-party is‐
         sues.  Default value is whichever IDs are listed in the .editorconfig file.  For a list of built-in an‐
         alyzer 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,  and  error.   The  default
         value is warn.

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/

                                                   2023-10-25                                   dotnet-format(1)