Code Formatting in Visual Studio

You could try the CodeMaid extension to Visual Studio.

This does code cleaning with the following steps:

  1. Remove unused using statements

  2. Sort using statements

  3. Add unspecified access modifiers

  4. Add blank line padding

  5. Remove blank lines adjacent to braces

  6. Run Visual Studio formatting

  7. Remove consecutive blank lines

  8. Remove end of line whitespace

  9. Update endregion tags

So you get Visual Studio's built-in reformatting plus lots of other tidying in one go. I expect there are other tools that do the same thing. I've been using CodeMaid for a while now and it's both fast and reliable.


It sounds like you want to format the entire document in Visual Studio (this feature is some times referred to as pretty printing). If so then you can use the menu command. Edit -> Advanced -> Format Document. This is typically bound to the key stroke CTRL+KCTRL+D