CSharpier Code Formatting Tool


In Visual Studio, formatting the content of the current file is generally done using the default shortcut Ctrl + K + D.

For me personally, code formatting is very important as it affects my reading experience. However, some of my colleagues and senior members of the company I work for do not pay much attention to code formatting, which leaves me speechless. Although I fix it when I see it, it results in unnecessary git commit records and wastes my time.

So, I need to find an automatic formatting tool similar to Prettier to help me automatically format all the code in the entire project before reading it.

By chance, I discovered CSharpier, and I can only say it's good! You can find clear information about it on their official website.

Next, let's see how to install it.

Installing CSharpier CLI#

Installing for a Single Project#

The advantage of doing this is that you can declare the dotnet tool dependencies for the current project, making it easier for others to restore the dependencies.

  1. Create a .config/dotnet-tools.json file:
dotnet new tool-manifest
  1. Install the CLI for the current project:
dotnet tool install csharpier


dotnet tool update csharpier

Global Installation#

Global installation:

dotnet tool install --global csharpier


dotnet tool update csharpier -g

Installing Visual Studio Extension#

Download the extension:

Then, you can right-click in the code and click the Reformat with CSharpier button to format the current file:

You can also customize the shortcut or automatically format on save. Refer to the extension homepage:


Execute the following command in the solution root directory or the specified project directory:

dotnet csharpier .


Formatting Configuration#

If you need to modify the default formatting parameters, you need to add a configuration file to the project. Currently, there are 3 supported formats:

I'm using a YAML file, so I create a .csharpierrc file in the root directory and copy the following configuration into it:

printWidth: 140
useTabs: false
tabWidth: 4
endOfLine: auto

For more configurations, you can check

Ignoring File Configuration#

To ignore specific files and folders and not perform formatting on them, you can add a .csharpierignore file. The file content follows the gitignore syntax, for example:


Of course, CSharpier CLI has some default ignore configurations, refer to:

If you want to ignore a certain section of code in a formatting file, add the following comment (reference):

// csharpier-ignore

It can also be used to call the API by installing the Nuget package to write a program that formats code. Refer to:

IDE Integration#

The official website also provides plugins for some IDEs, refer to:


CSharpier has many features, including support for MsBuild Package, Pre-commit Hook, Continuous Integration, and more. Due to time constraints, I will stop here.

Known Issues#

  • Unable to remove extra line breaks


Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.