Dan Dan - 29 days ago 16
C# Question

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

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?

Answer

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 http://github.com/timabell/vs-formatter-macro More info at http://wiki.github.com/timabell/vs-formatter-macro

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