So, I have gotten this question a couple of times... "How can I add my own custom menu item to a TFS Build Automation context menu?" Yes, this is possible and not really that difficult. We even added some extensibility in 2010 to make this an even better experience. So, here are the steps that I followed and some tips along the way.
First you need a Visual Studio package (I think an addin will work too, but I haven’t tried that).
Then, I changed the code to query for the IVsTeamFoundationBuild interface that the Build package provides.
private void MenuItemCallback(object sender, EventArgs e)
{
String message = null;
IVsTeamFoundationBuild vsTfBuild = (IVsTeamFoundationBuild)GetService(typeof(IVsTeamFoundationBuild));
if (vsTfBuild != null)
message = "got it!";
}
else
message = "Unable to get vsTfBuild.";
// Show a Message Box to prove we were here
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
Guid clsid = Guid.Empty;
int result;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
0,
ref clsid,
"BuildIntegrationPackage",
message,
string.Empty,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
OLEMSGICON.OLEMSGICON_INFO,
0, // false
out result));
Next, I changed the vsct file that defines the menu to move it to the Build Explorer context menu.
<Groups>
<Group guid="guidBuildIntegrationPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidCompletedBuilds" id="menuCompletedBuilds"/>
</Group>
</Groups>
<!-- This is the Build Explorer Menu. -->
<GuidSymbol name="guidCompletedBuilds" value="{34586048-8400-472e-BBBF-3AE30AF8046E}" >
<IDSymbol name="menuCompletedBuilds" value="0x105"/>
</GuidSymbol>
Then, all you have to do is write the code in your menu handler.
IBuildDetail[] builds = vsTfBuild.BuildExplorer.CompletedView.SelectedBuilds;
if (builds.Length == 1)
message = "Got Build: " + builds[0].BuildNumber;
message = "Got " + builds.Length.ToString() + " Builds";
After doing all of that, I have a menu group at the bottom of the Completed Builds context menu that shows a message with the build number or number of builds that are selected. I didn’t cover deployment of the VS package here. You will have to look that up, but it should be pretty straight forward and well documented.
Happy coding!