Visual Studio code formatting options per solution, directory and file

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:

Code formatting options in Visual Studio 2013

Code formatting options in Visual Studio 2013

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:

Saved code formatting options by Rebracer in Visual Studio 2013

Saved code formatting options by Rebracer in Visual Studio 2013

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
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).


Organize Visual Studio tabs with Tabs Studio add-in

This entry was posted in Reviews and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s