我正在编写一个扩展构建资源管理器的 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;
}
- 有没有办法获取构建列表?
- 更一般地说,有没有办法获得一些“这个上下文菜单所属的窗口”?目前我只是在 VS 的某些部分环顾四周,我认为会有构建......