Is there an automatic code formatter for C#?
Further to @Chris Karcher's answer - you can also automatically format the whole document by hitting Ctrl+K, Ctrl+D.
These formatting features work on a variety of file formats - it works wonders on ugly HTML.
For Visual Studio, take a look at ReSharper. It's an awesome tool and a definite must-have. Versions after 4.0 have the code formatting and clean-up feature that you are looking for. There's also plugin integration with StyleCop, including formatting settings file.
You'll probably want Agent Smith plugin as well, for spell-checking the identifiers and comments. ReSharper supports per-solution formatting setting files, which can be checked into version control system and shared by the whole team. The keyboard shortcut for code cleanup is Ctrl + E, C.
In 'vanilla' Visual Studio, the current file can be automatically formatted with Ctrl + K, Ctrl + D, and Ctrl + K, Ctrl + F formats the selected text.
As for a runs-everywhere command line tool to be used with commit hooks, try NArrange. It's free, can process whole directories at once and runs on Mono as well as on Microsoft .NET.
Some people also use the Artistic Style command line tool, although it requires Perl and works better with C/C++ code than with C#.
The .NET Foundation just released their code formatting tool on GitHub
https://github.com/dotnet/codeformatter
It uses the Roslyn compiler services to parse project documents and convert them to their expected formatting conventions. They're applying this to some of the very old CLR code in order to make all the projects consistent.
Another option: NArrange;
- free
- console based (so good for commit hooks etc, but can still be used as an "External Tool" in VS)
- flexible config file