0

我正在编写一个扩展构建资源管理器的 Visual Studio 2012 加载项 - 基本上,我为每个构建(已完成或正在运行,但未排队)添加一个上下文菜单选项。在一篇关于在 VS2010 中执行此操作的博客文章之后,我设法为出现在 Builder Explorer 中的构建这样做 - 万岁!

现在,我的上下文菜单也出现在 Team 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 的某些部分环顾四周,我认为会有构建......
4

1 回答 1

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;
于 2013-05-14T09:35:14.980 回答