Formatting - at once - all the files in a Visual Studio project

Viewed 45869

I am interested in formatting all the files in a Visual Studio (ver. 2005) project all at once.

Currently, there is a way to format a single document by doing something like Edit->Advanced->Format Document. However, I don't see a single command to format all the files of a project all at once.

Any idea how to do that?

6 Answers

Tim Abell wrote a macro to do this on his blog:

Here's a handy macro script for visual studio I knocked together today. It runs "edit, format document" on every document of the listed file types.

You have to keep an eye on it as it's interactive and does sometimes pop up a message and wait for an answer.

You can get the vb file at https://github.com/timabell/vs-formatter-macro More info at https://github.com/timabell/vs-formatter-macro/wiki

The original code is available at the blog post. Note that this is older than the version available on github above.

If anyone is still interested in this question, Visual Studio 2019 brought this functionality through a feature called Code Cleanup!

Just run Code Cleanup for Solution!

And you can also create multiple clean profiles and define which actions happen in each one.

There's a new way to format all files in a Visual Studio project using the dotnet CLI:

  1. Install dotnet format by running the following command:
    dotnet tool install -g dotnet-format
  2. Run it, replacing ProjectFile.csproj with the path to your project file, with the following command line:
    dotnet format ProjectFile.csproj
Related