How to change the background color of toolbars and menus in Visual Studio depending on the path (branch) of the loaded solution?

I often have several instances of Visual Studio open in different areas of our software. The branch name is mapped to a folder in the file system that contains the solution file.

I want to quickly say the branch I'm on, so that it's hard to avoid!

+4
source share
2 answers

I do not think that it is possible to conditionally change the colors of the menu / toolbar in Visual Studio based on the currently loaded solution. The excellent Visual Studio color theme editor gives you the ability to change the color scheme of the entire environment, but does not support the kind of fine-grained control you are looking for. All instances of Visual Studio will have the same color scheme applied to them.

The only thing I know about what can do what you need is Microsoft's Power Tools performance extension . Among dozens of features (most of which you can turn off if you don't like it or conflict with other extensions that you have already installed), it also supports extensive tab settings (what they call the Tab Well user interface ").

In particular, it allows you to β€œcolor tabs according to their design or according to regular expressions :

This option allows you to colorize the tabs according to the project to which they belong. This is especially useful when sorting tabs by project, because it allows you to immediately identify different groups of project documents. You can also customize regular expressions and assign colors to each one. If the tab name matches the configured regular expression, it will be colored with the assigned color.

Here is an example screenshot of some random tabs open, sorted and colored by project:

I personally did not try to configure this to work with multiple instances of Visual Studio, but I used it for several weeks (albeit with regular expression highlighting, and not according to the project) and it seems quite stable and customizable. I like the ability to immediately distinguish between different types of open files.

+5
source

If you work hard with branches, one of the most annoying mistakes you can make is to change the wrong branch. I have a project consisting of several solutions, each of which contains various user interface projects, each of which uses WCF as its back end, but is released as separate software. Whenever we release a new version of one of the user interfaces, we create a branch, so we can support patch, SP, etc.

A simple solution is to create a Visual Studio macro ( http://www.helixoft.com/blog/archives/32 ) that uses a regular expression to parse the full path of the solution file, search for a specific folder structure that identifies the branch. Here is the complete code:

Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, _ ByVal lpstring As String) As Boolean Private Sub showTitle(ByVal title As String) SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name) End Sub Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened Dim m As Match = Regex.Match( _ DTE.Solution.FullName, _ "Branch.*\\(?<project>.*)\\(?<branch>.*)\\(?<sln>.*)\.sln", _ RegexOptions.IgnoreCase) If (m.Success) Then Dim project As String = m.Groups("project").Value Dim version As String = m.Groups("branch").Value Dim sln As String = m.Groups("sln").Value showTitle(String.Format("BRANCH [{0}] - Project {1} - {2}", _ version, project, sln)) End If End Sub 

You need to paste this code into the macro editor, which opens from the menu "Tools" β†’ "Macros" β†’ "Macros" IDE

From an open editor, you simply double-click on MyMacros, expand EnvironmentEvents, and you can add your own code for each handler supported by Visual Studio.

If you look at the code, I will just put in a regular expression that allows me to parse the typical branch path structure that I have in my projects, where I have Branch \ someothertext \ nameoftheproject \ branchnumber \ solutionfile.sln.

NTN Greetings, Tarun

+1
source

All Articles