在Team Explorer的“我的版本”中查找版本 [英] Finding builds in Team Explorer's "My Builds"

查看:123
本文介绍了在Team Explorer的“我的版本”中查找版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Visual Studio 2012外接程序,该外接程序扩展了Build Explorer-基本上,我为每个构建(已完成或正在运行,但未排队的)都添加一个上下文菜单选项。以下有关在VS2010中执行此操作的博客文章,我设法对出现在Builder Explorer中的版本-hooray做到了!

I'm writing a Visual Studio 2012 add-in which extends Build Explorer - basically, I add a context menu option for every build (completed or running, but not queued). Following a blog post about doing this in VS2010, I managed to do so for builds that appear in Builder Explorer - hooray!

现在,我的上下文菜单也出现在Team Explorer的 Builds 页面, My Builds 部分。但是,当我得到回调时,我找不到任何地方的实际构建!

Now, my context menu also appear in Team Explorer's Builds pages, My Builds section. However, when I get the callback, I can't find the actual builds anywhere!

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

Here's my beforeQueryStatus event handler, where I try to find out whether I have a build to show or not:

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的某些部分中四处逛逛,我认为它们会生成...


推荐答案

我设法通过反射获得了构建:

I managed to get the build using reflection:

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;

这篇关于在Team Explorer的“我的版本”中查找版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆