Visual Studio supports only one global set of code formatting options. If you work on several projects/solutions with different formatting styles, you need to change global text formatting options each time you change projects:
If you work on a small fixed number of projects, you can automate options change with a macro or Visual Commander command, see Setting Indent Width and Tabs/Spaces Quickly Using Macros by Alexander Groß:
Dim textEditor As Properties textEditor = DTE.Properties("TextEditor", "AllLanguages") textEditor.Item("IndentStyle").Value = vsIndentStyle.vsIndentStyleSmart textEditor.Item("TabSize").Value = 4 textEditor.Item("IndentSize").Value = 2 textEditor.Item("InsertTabs").Value = False
The new Rebracer extension by Schabse S. Laks can store code formatting options in a separate file in the solution directory and automatically load these options with the solution. If you want to set solution specific formatting options, just change global Visual Studio options and Rebracer will remember them for your solution. You can store the Rebracer.xml file with saved options in your source control repository along with the solution and share with others:
You can download Rebracer from Visual Studio Gallery. Source code and additional FAQ are available on GitHub.
EditorConfig Visual Studio extension supports per directory and per file code formatting settings based on the EditorConfig standard. When you open or activate a document in Visual Studio, EditorConfig sets Visual Studio text formatting options based on the .editorconfig file stored with your source files:
; Top-most EditorConfig file root = true ; 4-column space indentation [*.cs] indent_style = space indent_size = 4
Only indent_style, indent_size, tab_width and end_of_line text formation options are supported. Unfortunately, the current version 0.3.1 on Visual Studio Gallery doesn’t work. You can download patched v0.4.1 for Visual Studio 2013 here (I downloaded it here and removed dependency on MPF 11.0 from extension.vsixmanifest).