Skip to content
Home for the dotnet-format command
Branch: master
Clone or download
dotnet-maestro Update dependencies from https://github.com/dotnet/roslyn build 20190…
…419.4 (#108)

- Microsoft.NETCore.Compilers - 3.1.0-beta3-19219-04
Latest commit 3684ac0 Apr 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
eng Update dependencies from https://github.com/dotnet/roslyn build 20190… Apr 19, 2019
src Code cleanup (#86) Apr 9, 2019
tests Code cleanup (#86) Apr 9, 2019
.editorconfig
.gitattributes Add .gitattributes Mar 25, 2019
.gitignore Add .packages folder to git ignore list (#119) Oct 16, 2018
Build.cmd Minor samples repo cleanup (#94) Oct 5, 2018
CODE_OF_CONDUCT.md Add Code of Conduct (#6) Aug 21, 2018
Directory.Build.props
Directory.Build.targets Arcadify by adding reference to the base template (#4) Aug 8, 2018
LICENSE.TXT Initialize repository Jul 25, 2018
NuGet.config Rename NuGet.Config to NuGet.config (#133) Oct 19, 2018
README.md Fix BOM in readme.md Apr 3, 2019
Restore.cmd
THIRD-PARTY-NOTICES.TXT Initialize repository Jul 25, 2018
Test.cmd adding common scripts Apr 19, 2019
azure-pipelines-integration.yml Add integration test runner (#88) Apr 9, 2019
azure-pipelines-official.yml Normalize source files Mar 25, 2019
azure-pipelines.yml this should speed up CI Apr 19, 2019
build.sh Fix build.sh execute permission (#169) Oct 29, 2018
format.sln Normalize source files Mar 25, 2019
global.json Update dependencies from https://github.com/dotnet/arcade build 20190… Apr 19, 2019
restore.sh adding common scripts Apr 19, 2019
test.sh adding common scripts Apr 19, 2019

README.md

dotnet-format

Nuget

MyGet

Branch Windows (Debug) Windows (Release) Linux (Debug) Linux (Release) Localization (Debug) Localization (Release)
master Build Status Build Status Build Status Build Status Build Status Build Status

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.

How To Install

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

Installing Development Builds

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 3.0.5-prerelease.19203.5 --add-source https://dotnet.myget.org/F/format/api/v3/index.json

How To Use

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 option. You can control how verbose the output will be by using the -v option.

Usage:
  dotnet-format [options]

Options:
  -w, --workspace    The solution or project file to operate on. If a file is not specified, the command will search
                     the current directory for one.
  -v, --verbosity    Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and
                     diag[nostic]
  --dry-run          Format files, but do not save changes to disk.
  --check            Terminates with a non-zero exit code if any files were formatted.
  --files            A comma separated list of relative file paths to format. All files are formatted if empty.
  --version          Display 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 -w <workspace> Formats a specific project or solution.
dotnet format -v diag Formats with very verbose logging.
dotnet format --files Programs.cs,Utility\Logging.cs Formats the files Program.cs and Utility\Logging.cs
dotnet format --check --dry-run Formats but does not save. Returns a non-zero exit code if any files would have been changed.

How To Uninstall

You can uninstall the tool using the following command.

dotnet tool uninstall -g dotnet-format

How To Build From Source

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.3.0.0-dev.nupkg'.
# Use the value that is in the form `3.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.

You can’t perform that action at this time.