<p>In my work I deal mostly with C# code nowadays, with a sprinkle of java from time to time. What I absolutely love about Eclipse (and I know people using it daily love it even more) is a sophisticated code formatter, able to mould code into any coding standard one might imagine. Is there such a tool for C#? Visual Studio code formatting (Crtl+K, Crtl+D) is subpar and StyleCop only checks the source without fixing it.</p>

<p>My dream tool would run from console (for easy inclusion in automated builds or pre-commit hooks and for execution on Linux + Mono), have text-file based configuration easy to store in a project repository and a graphical rule editor with preview - just like the Eclipse Code Formatter does.</p>

[{'answer_id': 30111, 'author': 'JamesSugrue', 'author_id': 1075, 'author_profile': 'https://Stackoverflow.com/users/1075', 'pm_score': 2, 'selected': False, 'text': '<p>Not directly, but I use the <a href="http://www.agentsmithplugin.com/" rel="nofollow noreferrer">Agent Smith</a> plugin for R# to do this. Unfortunately, R# isn\'t free. </p>\n'}, {'answer_id': 30114, 'author': 'FantaMango77', 'author_id': 2374, 'author_profile': 'https://Stackoverflow.com/users/2374', 'pm_score': 7, 'selected': True, 'text': '<p>For Visual Studio, take a look at <a href="http://www.jetbrains.com/resharper" rel="nofollow noreferrer">ReSharper</a>. 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 <a href="http://stylecopforresharper.codeplex.com/" rel="nofollow noreferrer">plugin integration with StyleCop</a>, including formatting settings file.</p>\n\n<p>You\'ll probably want <a href="https://resharper-plugins.jetbrains.com/packages/ReSharper.AgentSmith/" rel="nofollow noreferrer">Agent Smith plugin</a> 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 <kbd>Ctrl</kbd> + <kbd>E</kbd>, <kbd>C</kbd>.</p>\n\n<p>In \'vanilla\' Visual Studio, the current file can be automatically formatted with <kbd>Ctrl</kbd> + <kbd>K</kbd>, <kbd>Ctrl</kbd> + <kbd>D</kbd>, and <kbd>Ctrl</kbd> + <kbd>K</kbd>, <kbd>Ctrl</kbd> + <kbd>F</kbd> formats the selected text.</p>\n\n<p>As for a runs-everywhere command line tool to be used with commit hooks, try <a href="http://www.narrange.net/" rel="nofollow noreferrer">NArrange</a>. It\'s free, can process whole directories at once and runs on Mono as well as on Microsoft .NET.</p>\n\n<p>Some people also use the <a href="http://astyle.sourceforge.net/" rel="nofollow noreferrer">Artistic Style</a> command line tool, although it requires Perl and works better with C/C++ code than with C#.</p>\n'}, {'answer_id': 30140, 'author': 'Zack Peterson', 'author_id': 83, 'author_profile': 'https://Stackoverflow.com/users/83', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve heard only good things about <a href="http://www.jetbrains.com/resharper" rel="nofollow noreferrer">ReSharper</a>.  It\'s on my to-learn list.</p>\n'}, {'answer_id': 30144, 'author': 'Chris Karcher', 'author_id': 2773, 'author_profile': 'https://Stackoverflow.com/users/2773', 'pm_score': 3, 'selected': False, 'text': "<p>For me, <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>F</kbd> maps to Find in Files. When I need to format code, I highlight it and hit <kbd>Ctrl</kbd> + <kbd>K</kbd>, <kbd>Ctrl</kbd> + <kbd>F</kbd>.</p>\n\n<p>I understand this doesn't really address automated formatting. I just wanted to clarify for those who may not know this feature even exists in Visual&nbsp;Studio.</p>\n"}, {'answer_id': 30150, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 2, 'selected': False, 'text': '<p>Also take a look at <a href="http://blogs.msdn.com/sourceanalysis/" rel="nofollow noreferrer">Microsoft StyleCop</a></p>\n'}, {'answer_id': 30250, 'author': 'Ian Nelson', 'author_id': 2084, 'author_profile': 'https://Stackoverflow.com/users/2084', 'pm_score': 4, 'selected': False, 'text': "<p>Further to @Chris Karcher's answer - you can also automatically format the <em>whole document</em> by hitting <kbd>Ctrl</kbd>+<kbd>K</kbd>, <kbd>Ctrl</kbd>+<kbd>D</kbd>.</p>\n\n<p>These formatting features work on a variety of file formats - it works wonders on ugly HTML.</p>\n"}, {'answer_id': 608517, 'author': 'Jan', 'author_id': 20941, 'author_profile': 'https://Stackoverflow.com/users/20941', 'pm_score': 1, 'selected': False, 'text': '<p>I haven\'t tried this (found it through Google). It might work. <a href="http://www.semdesigns.com/Products/Formatters/CSharpFormatter.html" rel="nofollow noreferrer">http://www.semdesigns.com/Products/Formatters/CSharpFormatter.html</a>. It\'s fairly cheap at USD50, but a trial is not available.</p>\n'}, {'answer_id': 777064, 'author': 'majkinetor', 'author_id': 82660, 'author_profile': 'https://Stackoverflow.com/users/82660', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.sourceformat.com/" rel="nofollow noreferrer">http://www.sourceformat.com/</a></p>\n\n<p>This tool is around (~30$). I tried it and it works nice (with multiple languages).</p>\n\n<p>I like this tool the best because it doesn\'t check code file for correctness. I can post code snippets from the Internet and it will translate them correctly no matter if they are in missing parts of the code. Other tools I try complain in that cases. The tool can also be integrated easily into editors as it allows command line driving.</p>\n\n<p>Other tools:</p>\n\n<p><a href="http://www.polystyle.com/index.jsp" rel="nofollow noreferrer">http://www.polystyle.com/index.jsp</a></p>\n\n<p><a href="http://astyle.sourceforge.net/" rel="nofollow noreferrer">http://astyle.sourceforge.net/</a> (open source)</p>\n'}, {'answer_id': 777084, 'author': 'Simon Steele', 'author_id': 4591, 'author_profile': 'https://Stackoverflow.com/users/4591', 'pm_score': 1, 'selected': False, 'text': '<p>See this previous question:</p>\n\n<p><a href="https://stackoverflow.com/questions/27253/is-there-any-tool-for-reformatting-c-code">Is there any tool for reformatting C# code?</a></p>\n\n<p>Searching for [c#] astyle shows up some more previous questions too.</p>\n'}, {'answer_id': 777329, 'author': 'Marc Gravell', 'author_id': 23354, 'author_profile': 'https://Stackoverflow.com/users/23354', 'pm_score': 3, 'selected': False, 'text': '<p>Another option: <a href="http://www.narrange.net/" rel="noreferrer">NArrange</a>;</p>\n\n<ul>\n<li>free</li>\n<li>console based (so good for commit hooks etc, but can still be used as an "External Tool" in VS)</li>\n<li>flexible config file</li>\n</ul>\n'}, {'answer_id': 13578059, 'author': 'Vikram', 'author_id': 1826585, 'author_profile': 'https://Stackoverflow.com/users/1826585', 'pm_score': 0, 'selected': False, 'text': '<p>Here is an open source code formatting tool which has amazing features</p>\n\n<p><a href="http://www.codemaid.net/" rel="nofollow">CodeMaid</a></p>\n'}, {'answer_id': 18946209, 'author': 'NinjaCross', 'author_id': 203370, 'author_profile': 'https://Stackoverflow.com/users/203370', 'pm_score': 1, 'selected': False, 'text': '<p>Maybe you could be interested in <a href="http://visualstudiogallery.msdn.microsoft.com/0c5664a7-a723-4ac1-9932-d840dfafd6d5" rel="nofollow noreferrer">this free Addin</a> for Visual Studio 2010/2012.</p>\n'}, {'answer_id': 28422017, 'author': 'Paul Turner', 'author_id': 138578, 'author_profile': 'https://Stackoverflow.com/users/138578', 'pm_score': 5, 'selected': False, 'text': '<p>The <a href="https://en.wikipedia.org/wiki/.NET_Foundation" rel="noreferrer">.NET Foundation</a> just released their code formatting tool on GitHub</p>\n\n<p><a href="https://github.com/dotnet/codeformatter" rel="noreferrer">https://github.com/dotnet/codeformatter</a></p>\n\n<p>It uses the <a href="https://en.wikipedia.org/wiki/.NET_Compiler_Platform" rel="noreferrer">Roslyn</a> compiler services to parse project documents and convert them to their expected formatting conventions. They\'re applying this to some of the very old <a href="https://en.wikipedia.org/wiki/Common_Language_Runtime" rel="noreferrer">CLR</a> code in order to make all the projects consistent.</p>\n'}, {'answer_id': 42583484, 'author': 'Alexandre Nascimento', 'author_id': 7459228, 'author_profile': 'https://Stackoverflow.com/users/7459228', 'pm_score': 0, 'selected': False, 'text': '<p>If you want to do it online, have a <a href="http://www.freecodeformat.com/c-format.php" rel="nofollow noreferrer">freecodeformat</a>.</p>\n'}]
['https://Stackoverflow.com/questions/30101', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3205/']