locked
VS2013 / Team Explorer vsix - How to get the currently selected build definition? RRS feed

  • Question

  • Greetings,

    My goal with a simple extension is to right-click any build definition and if my "Show Build Def Stats" menu item is selected, pop a message box with some summary details I plan to pull from the IBuildDefinition interface.

    I'm missing something fundamental I'm sure, but I cannot figure out how in the menu handler the actual build definition that I clicked on.

    The menu command is added where I want it successfully:

    Team Explorer - Get Build Definition Stats context menu command

    Symbol info used to get this there:

        <!-- This is the Build Definition Context Menu -->
        <GuidSymbol name="guidTeamExplorerBuildDefContextMenu" value="{34586048-8400-472E-BBBF-3AE30AF8046E}" >
          <IDSymbol name="menuBuildDefinitionContext" value="0x109"/>
        </GuidSymbol>

    I am stumped as to how to get the fact that I clicked the "ISRepository" build definition in either the Initialize() or MenuItemCallBack() methods, I haven't come across the right service or container object that I recognize.

    Much obliged!

    --Jordan

    Tuesday, March 31, 2015 2:21 PM

Answers

  • I have been investigating this for a while using .NET Reflector and finally I got it:

    In VS 2013, add references to the following assemblies in the folder C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer:

    Microsoft.TeamFoundation.Controls.dll
    Microsoft.TeamFoundation.Build.Controls.dl

    And then use this code:

    Microsoft.TeamFoundation.Controls.ITeamExplorer teamExplorer;
    Microsoft.TeamFoundation.Controls.ITeamExplorerPage teamExplorerPage;
    Microsoft.TeamFoundation.Build.Controls.Extensibility.IBuildsPageExt buildsPageExt;
    
    teamExplorer = base.GetService(typeof(Microsoft.TeamFoundation.Controls.ITeamExplorer)) as Microsoft.TeamFoundation.Controls.ITeamExplorer;
    
    teamExplorerPage = teamExplorer.CurrentPage;
            
    buildsPageExt = teamExplorerPage.GetExtensibilityService(typeof(Microsoft.TeamFoundation.Build.Controls.Extensibility.IBuildsPageExt)) as Microsoft.TeamFoundation.Build.Controls.Extensibility.IBuildsPageExt;
    
    foreach (Microsoft.TeamFoundation.Build.Controls.Extensibility.IDefinitionModel definitionModel in buildsPageExt.SelectedDefinitions)
    {
       System.Windows.Forms.MessageBox.Show(definitionModel.Name);
    }
    


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Wednesday, April 1, 2015 11:49 PM

All replies

  • Try IVsTeamExplorer interface

    Then TeamExplorerWindow property, which returns IVsUIHierarchyWindow interface and then GetCurrentSelection


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Tuesday, March 31, 2015 8:41 PM
  • Carlos, thank you for the reply.

    IVsTeamExplorer appears to have been deprecated as of the 2012 version.

    The [ObsoleteAttritbute] decoration in the MSDN documentation you linked to suggests using ITeamFoundationContextManager instead. This looks like it's getting me closer, but its CurrentContext property only nets me the current Team Project Collection and Team Project that the selected build definition is in, but nothing for the currently selected one (or hierarchy objects that I could find).

    Are you aware of any other TeamFoundationContext interfaces that returns IVsUIHierarchyWindow (didn't come across one on MSDN myself).

    Thanks,

    --Jordan


    Wednesday, April 1, 2015 4:03 PM
  • I have been investigating this for a while using .NET Reflector and finally I got it:

    In VS 2013, add references to the following assemblies in the folder C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer:

    Microsoft.TeamFoundation.Controls.dll
    Microsoft.TeamFoundation.Build.Controls.dl

    And then use this code:

    Microsoft.TeamFoundation.Controls.ITeamExplorer teamExplorer;
    Microsoft.TeamFoundation.Controls.ITeamExplorerPage teamExplorerPage;
    Microsoft.TeamFoundation.Build.Controls.Extensibility.IBuildsPageExt buildsPageExt;
    
    teamExplorer = base.GetService(typeof(Microsoft.TeamFoundation.Controls.ITeamExplorer)) as Microsoft.TeamFoundation.Controls.ITeamExplorer;
    
    teamExplorerPage = teamExplorer.CurrentPage;
            
    buildsPageExt = teamExplorerPage.GetExtensibilityService(typeof(Microsoft.TeamFoundation.Build.Controls.Extensibility.IBuildsPageExt)) as Microsoft.TeamFoundation.Build.Controls.Extensibility.IBuildsPageExt;
    
    foreach (Microsoft.TeamFoundation.Build.Controls.Extensibility.IDefinitionModel definitionModel in buildsPageExt.SelectedDefinitions)
    {
       System.Windows.Forms.MessageBox.Show(definitionModel.Name);
    }
    


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Wednesday, April 1, 2015 11:49 PM
  • Fantastic Carlos, thanks very much for sharing!  Didn't realize I was missing that assembly in my search, I'm definitely itching to play with Reflector more.

    Thanks again,

    --Jordan

    Thursday, April 2, 2015 12:34 AM