Branch | Windows (Debug) | Windows (Release) | Linux (Debug) | Linux (Release) | Localization (Debug) | Localization (Release) |
---|---|---|---|---|---|---|
master |
dotnet-format
is a code formatter for dotnet
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. At this time dotnet-format
is able to format C# and Visual Basic projects with a subset of supported .editorconfig options.
- Added an imports formatter for sorting imports.
- Format now runs on the latest installed Runtime.
--check
and--dry-run
have combined into a single option.--include
and--exclude
use space-separated paths instead of comma-separated.
- Added warning to use the default argument instead of
--workspace
option. Usedotnet format ./format.sln
instead ofdotnet format -w ./format.sln
- Added warning to use the default argument to specify the folder path when using the
--folder
option. Usedotnet format ./src -f
instead ofdotnet format -f ./src
- Added warning to use
--include
instead of--files
alias. - Added warning to use
--check
instead of--dry-run
alias.
- Add Imports Formatter (693)
- Always run on the latest Runtime (694)
- Move to Roslyn's editorconfig support (590)
- Command line argument for solution/project as positional argument (681)
- Add option to format generated code files. (673)
- Produce a binlog when verbosity is set to detailed (605)
- Fix #581 - Add final newline false positive (633)
- Combine --check and --dry-run into a single option. (541)
- Use space-separated paths instead of comma-separated for --include and --exclude (551)
- Support loading commandline options from response files (552)
- Support file globbing in --include and --exclude options (555)
The dotnet-format
nuget package is published to nuget.org.
You can install the tool using the following command.
dotnet tool install -g dotnet-format
Development builds of dotnet-format
are being hosted on myget. You can visit the dotnet-format myget page to get the latest version number.
You can install the tool using the following command.
dotnet tool install -g dotnet-format --version 5.0.135301 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
By default dotnet-format
will look in the current directory for a project or solution file and use that as the workspace to format. If more than one project or solution file is present in the current directory you will need to specify the workspace to format using the -w
or -f
options. You can control how verbose the output will be by using the -v
option.
Usage:
dotnet-format [options] [<workspace>]
Arguments:
<workspace> A path to a solution file, a project file, or a folder containing a solution or project file. If a path is not specified then the current directory is used.
Options:
--folder, -f Whether to treat the `<workspace>` argument as a simple folder of files.
--fix-style, -fs <severity> Run code style analyzers and apply fixes.
--fix-analyzers, -fa <severity> Run 3rd party analyzers and apply fixes.
--include <include> A list of relative file or folder paths to include in formatting. All files are formatted if empty.
--exclude <exclude> A list of relative file or folder paths to exclude from formatting.
--check Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.
--report <report> Accepts a file path, which if provided, will produce a json report in the given directory.
--verbosity, -v <verbosity> Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]
--version Show version information
Add format
after dotnet
and before the command arguments that you want to run:
Examples | Description |
---|---|
dotnet format | Formats the project or solution in the current directory. |
dotnet format <workspace> | Formats a specific project or solution. |
dotnet format <workspace> -f | Formats a particular folder and subfolders. |
dotnet format <workspace> --fix-style warn | Formats and fixes codestyle analyzer warnings. |
dotnet format <workspace> --fix-analyzers | Formats and fixes 3rd party analyzer errors. |
dotnet format -v diag | Formats with very verbose logging. |
dotnet format --include Programs.cs Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs |
dotnet format --check | Formats but does not save. Returns a non-zero exit code if any files would have been changed. |
dotnet format --report <report-path> | Formats and saves a json report file to the given directory. |
You can uninstall the tool using the following command.
dotnet tool uninstall -g dotnet-format
You can build and package the tool using the following commands. The instructions assume that you are in the root of the repository.
build -pack
# The final line from the build will read something like
# Successfully created package '..\artifacts\packages\Debug\Shipping\dotnet-format.5.0.0-dev.nupkg'.
# Use the value that is in the form `5.0.0-dev` as the version in the next command.
dotnet tool install --add-source .\artifacts\packages\Debug\Shipping -g dotnet-format --version <version>
dotnet format
Note: On macOS and Linux,
.\artifacts
will need be switched to./artifacts
to accommodate for the different slash directions.