在团队资源管理器的“我的构建”中查找构建

时间:2013-05-09 16:48:06

标签: visual-studio-2012 add-in tfsbuild tfs2012

我正在编写一个扩展Build Explorer的Visual Studio 2012加载项 - 基本上,我为每个构建添加了一个上下文菜单选项(已完成或正在运行,但未排队)。在a blog post about doing this in VS2010之后,我设法为在Builder Explorer中出现的构建实现了这一点 - 万岁!

现在,我的上下文菜单也出现在团队资源管理器的Builds页面My Builds部分中。但是,当我收到回调时,我无法在任何地方找到实际构建版本!

这是我的beforeQueryStatus事件处理程序,我试图找出是否有要显示的构建:

private void OpenCompletedInBuildExplorerBeforeQueryStatus(object sender, EventArgs e)
{
    var cmd = (OleMenuCommand)sender;
    var vsTfBuild = (IVsTeamFoundationBuild)GetService(typeof(IVsTeamFoundationBuild));

    // This finds builds in Build Explorer window
    cmd.Enabled = (vsTfBuild.BuildExplorer.CompletedView.SelectedBuilds.Length == 1
                && vsTfBuild.BuildExplorer.QueuedView.SelectedBuilds.Length == 0); // No build _requests_ are selected

    // This tries to find builds in Team Explorer's Builds page, My Builds section
    var teamExplorer = (ITeamExplorer)GetService(typeof(ITeamExplorer));
    var page = teamExplorer.CurrentPage as Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerPageBase;  
    var vm = page.ViewModel;
    // does not compile: 'Microsoft.TeamFoundation.Build.Controls.BuildsPageViewModel' is inaccessible due to its protection level
    var vm_private = vm as Microsoft.TeamFoundation.Build.Controls.BuildsPageViewModel;
    // But debugger shows that if it did, my builds would be here:
    var builds = vm_private.MyBuilds;
}
  1. 有没有办法获取构建列表?
  2. 更一般地说,有没有办法获得一些“这个上下文菜单所属的窗口”?目前我只是在VS的部分地方四处寻找我认为会有建造......

1 个答案:

答案 0 :(得分:0)

我设法使用反射进行构建:

var teamExplorer = (ITeamExplorer)GetService(typeof(ITeamExplorer));

var BuildsPage = teamExplorer.CurrentPage as Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerPageBase;
var PageViewModel = BuildsPage.ViewModel as Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerPageViewModelBase;
    // PageViewModel is actually Microsoft.TeamFoundation.Build.Controls.BuildsPageViewModel. But, it's private, so get SelectedBuilds through reflection
var SelectedBuilds = PageViewModel.GetType().GetProperty("SelectedBuilds").GetValue(PageViewModel) as System.Collections.IList;
if (SelectedBuilds.Count != 1)
{
    cmd.Enabled = false;
    return;
}

object BuildModel = SelectedBuilds[0];
    // BuildModel is actually Microsoft.TeamFoundation.Build.Controls.BuildModel. But, it's private, so get UriToOpen through reflection
var BuildUri = BuildModel.GetType().GetProperty("UriToOpen").GetValue(BuildModel) as Uri;
// TODO: Use BuildUri...

cmd.Enabled = true;
相关问题