Freigeben über


Another Visual Studio IDE Tip

Paul Harrington, our good dev lead over on the IDE team has recently written a simple macro to solve a customer's problem. He was kind enough to let me know about this so I can share it with you.

The customer wrote:

Many of us work on multiple projects at the same time, and some of those have different coding conventions. For example, you might be involved in a work-related project that uses company-defined conventions, but also participate on open source projects with their own coding styles. However, currently visual studio settings for Code Formatting are global and cannot be easily overridden.

Here’s what Paul came up with:

For each solution, create a .vssettings file containing the editor options you want to modify and add it to the solution. Then create a macro hooked up to the “Solution Opened” event to import the .vssettings file automatically.

The macro is really simple (add it to the EnvironmentEvents module):

    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

I hope some of you will find this useful! Paul, thanks for the tip!

- James

Comments

  • Anonymous
    January 28, 2007
    Hey James ... excelent tip !! Thanks in advance Bye from Spain