Make Per-Solution Code Formatting Settings - by Tomas Restrepo

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 253597 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 1/24/2007 4:39:53 AM
Access Restriction Public


Make available multiple code formatting profiles and allow them to be associated with a solution, specifying conventions such as tab settings, code formatting settings and other basic text editing tools.

See for a longer description.
Sign in to post a comment.
Posted by kwaclaw on 11/27/2013 at 6:15 AM
I find myself looking for this feature frequently, as I work on multiple projects with different code formatting requirements.
I know I am not alone with this.

This has to be a part of the standard VS features.
Its incomprehensible to me that this was declared a "Won't fix" issue.
Posted by Andrew L Arnott on 9/1/2008 at 10:44 AM
I don't think this solution works at all... since the code formatting settings DO NOT export into the .vssettings file. C# settings in general do, but not formatting rules.
Posted by Boris Byk on 6/10/2008 at 11:24 AM
that works, but absolutely inconvenient to maintain in a large team. please reopen the feedback - it should be imply in *.sln file directly instead.
Posted by Microsoft on 1/26/2007 at 7:16 PM
Thanks for the suggestion. This is already possible today, albeit with a little bit of macro magic.
There are two pieces to this.
1. For each solution add a .vssettings file with a well-known name. e.g. "VSEditorFormatting.vssettings"
2. Add a macro, tied to the solution opened event that imports that vssettings file.

Here are some details:

Start by opening your solution. Make a note of the path where your .sln file is (you can click on the Solution node in the Solution Explorer tool window and view its Path in the Properties toolwindow)

To create the .vssettings file:
1. Set up the editor options the way you want them.
2. Export these settings using the "Tools/Import and Export Settings..." wizard like so:
2a. Select "Export selected environment settings" and click Next
2b. In the tree view, uncheck "All Settings" and expand the Options/Text Editor node
2c. Check only the nodes for which you want to save settings. The description pane on the right can help you decide which categories you need.
2d. Click Next
2e. Name the file "VSEditorFormatting.vssettings"
2f. For the directory, click the "Browse..." button and use the file dialog to navigate to the folder containing your solution (.sln) file. Click OK
2g. Click "Finish"

Now you have created the .vssettings file, add it to the associated solution like this:
1. Show the Solution Explorer if it isn't already (Ctrl+Alt+L)
2. Right click on the Solution node (at the top)
3. Select "Add Existing Item..."
4. Browse to the .vssettings file you saved earlier and click "Add"

At this point, if your project is under source code control you might want to add this new .vssettings file to your source code control.

Now, here comes the macro magic!
1. Launch the Macros IDE (Alt+F11)
2. In the "Project Explorer" toolwindow, double-click on "MyMacros" to expand it
3. Double-click on "EnvironmentEvents" to show the source code
4. Add this code just above the "End Module" statement at the end of the file:

    Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
        Dim item As ProjectItem = DTE.Solution.FindProjectItem("VsEditorFormatting.vssettings")
        If Not item Is Nothing Then
            Dim name = item.FileNames(1)
            DTE.ExecuteCommand("Tools.ImportandExportSettings", "/import:""" & name & """")
        End If
    End Sub

What this does is hook up a handler for the "Solution.Opened" event. When it fires, the code looks for your "VsEditorFormatting.vssettings" file in the solution and, if it's found, it imports that file.

5. Close the Macros IDE
6. Close Visual Studio (you will get prompted to save "MyMacros")

Now, every time you open a solution containing a "VsEditorFormatting.vssettings" file, it will be automatically imported for you. You will can need to share this macro with your co-workers so that they can take advantage of it.

Hope that helps.

- Visual Studio Platform Team