How to change the title bar text of Visual Studio

Solution 1:

I just created a small Visual Studio extension that can help: http://visualstudiogallery.msdn.microsoft.com/f3f23845-5b1e-4811-882f-60b7181fa6d6

This small extension will detect whenever two instances of Visual Studio are running and change the window title of Visual Studio to include the parent folder name of the solution. It will therefore change SolutionFolder - Microsoft Visual Studio into SolutionFolderParent\SolutionFolder - Microsoft Visual Studio.

This is particularly useful when branching a solution: it becomes possible to easily identify which branch you are working on, in the case where both would have the same solution name.

Official page here: http://erwinmayer.com/labs/visual-studio-2010-extension-rename-visual-studio-window-title/

Solution 2:

Check out latest release of VSCommands 2010 Lite. It introduced a feature called Friendly Solution Name where you can set up a regex pattern to extract branch name from folder structure and have it placed in Visual Studio main window title. More details: http://vscommands.com/releasenotes/3.6.8.0 and http://vscommands.com/releasenotes/3.6.9.0

MSDN Download Page

Solution 3:

Trying to set MainWindow.Caption throws an exception. You have to use the Win32 SetWindowText function to change the title, but beware: Visual Studio resets the title bar text at the drop of a hat, so you should implement a Timer to keep setting your desired text. The following code from the Connect class of the add-in will permanently (or, as long as the add-in is running) keep the title bar text as "Hello World!"

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    resetTitleTimer = new Timer(new TimerCallback(SetMainWindowTitle), "Hello world!", 0, 10);
}

[DllImport("user32.dll")]
private static extern bool SetWindowText(IntPtr hWnd, string lpString);
private void SetMainWindowTitle(object state)
{
    IntPtr hWnd = (IntPtr)_applicationObject.MainWindow.HWnd;
    SetWindowText(hWnd, "Hello World!");            
}

Solution 4:

I added a symbolic link with a different name targeting the solution file. Open the solution with the symbolic link and the window title has the symbolic link name.

In windows: mklink BlawBranch.sln Blaw.sln

EDIT: Found that a hard link breaks if target .sln file is updated by our source control. A symbolic link doesn't have the same problem.