Adding a command to the Source Control Explorer context menu

Update 2/26/2009: You can find a version of this sample addin that works with VS 2005 here. 

We’ve gotten some questions recently about how to interact with and extend our out-of-the-box version control functionality. For most users, the main hub of activity is the Source Control Explorer, so it makes sense for us to provide some sample code demonstrating how to add a command to the Source Control Explorer’s context menu. The sample additionally provides an add-in command framework making it easier to add commands to other parts of the version control user interface, such as the History window.

The new command added to the Source Control Explorer context menu in this sample is called “Multi Label” and is an extension of the “Quick Label” functionality provided in the downloadable Team Foundation Power Tools. With “Multi Label” you can label multiple items at once by selecting them in the Source Control Explorer’s right pane. Once the Multi Label dialog is up, you can add more paths to label by typing them in.

Here’s how to build and try out the add-in. 
1. On a machine with Visual Studio 2008 and Team Explorer installed, download and unzip Open the VersionControlExtensibility.sln file in Visual Studio.

2. Open the References node for the project in Solution Explorer, and see if any of the assemblies listed have the Warning icon next to them. Microsoft.VisualStudio.TeamFoundation.VersionControl.dll is referenced and is not in the GAC, so you may need to remove and re-add this reference since the path you find it in varies. On my machine (64-bit), the assembly is in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies.extensibility1

3. Build the solution — you should end up with the VersionControlExtensibility.dll file in the bin/ directory.

Now you’re ready to install. Add-ins live in your My Documents\Visual Studio 2008\Addins folder on disk, and you’ll need to drop 2 files in that directory:

1. The VersionControlExtensibility.AddIn file (which is just an XML file with information about the add-in DLL)
2. The VersionControlExtensibility.dll file which you just built.

Restart Visual Studio 2008 if you have it open, and the add-in will be loaded. Right-click on any item in the Source Control Explorer and you should see “Multi Label…” on the list.


To add your own custom command to the SCE context menu, subclass SCEAddInCommand and provide implementations for the following properties.

// From AddInCommand — base class for all commands
override String Name { get { return “MyCommandName”; } }
override String ButtonText { get { return “Text for Context Menu…”; } }
override String ToolTip { get { return “A short description of my command”; } }
override bool UseMSOIcon { get { return false; } } // Can be used to provide an icon for your command
public override int IconIndex { get { return -1; } } // Can be used to provide an icon for your command

// From SCEAddInCommand — derived from AddInCommand; base class for commands hooking the SCE context menu
override int SCEContextMenuPosition { get { return 5; } }

You’ll also need implementations for the following methods from AddInCommand.

// Called by Visual Studio to determine whether your command is enabled, disabled, or invisible.
public override void QueryStatus(EnvDTE.vsCommandStatusTextWanted neededText, ref EnvDTE.vsCommandStatus status, ref object commandText)
    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;

// Called by Visual Studio when your command is clicked.
public override void Exec(EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    handled = true;

Last, you’ll need to add your custom command in Connect.cs’s OnConnection method so that it’s created when the add-in is loaded. I’ve left a sample line there you can uncomment and modify to fit the name of your AddInCommand.

Thanks to Ed Hintz for designing the original version of this framework.

Comments (3)

  1. Greg Roberts says:

    Thanks for the good info here. I am curious on the tool tips issue. When you sample runs i don’t see the test tooltip so i don’t understand when it is meant to kick in.

    If you look at

    you will undertand the context of where i am coming from.

    ideally i would like to steal the tooltip for the "Source Code Explorer" .

    Thanks in advance.

  2. michael.dudek says:

    Hello, do you have a working version of this extension for VS 2010 please?

    Thanks for info.


  3. Satya Srikant Mantha says:


    Do you have some samples in VSIP packages for extending TFS 2010 Source Control? Specifically I am looking for adding new commands as you did in the above and also to extend existing commands like "Get Latest" in context menu.

    Thanks in advance


Skip to main content