My suggestion on per-solution code formatting settings for a (non-specified) future version of VS posted on connect was shot down fast: Only took two days for it to be closed as "Resolved (won't fix)". I knew that would happen but two things still bug me:

  1. Resolved (won't fix)? That's totally the wrong way to close a suggestion. I didn't report it as a bug (which you'd fix).
  2. Not even a comment or explanation of why it's not something even worth considering. Guess it was too stupid to even be worth looking into, then.

Oh well, live and learn. So much for taking the time to suggest improvements!

Update: Ahh, I did get a comment. Someone, however, has to learn that you'd be better off putting the comment first, closing the issue second. Thanks for saving us a lot of frustration :-).

Now, here's the MS response in all it's glory:


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.

Humm... OK, thanks, but no, that's not really what I wanted. Visual Studio already takes ages to start up without me trying to rewrite all the persistent settings each time!

Technorati tags:


Tomas Restrepo

Software developer located in Colombia.