如何从Visual Studio外部打开WorkItem(VS-Team Explorer)?

时间:2010-10-21 12:58:57

标签: c# tfs

我想使用C#代码从外部visual studio打开工作项。可能吗?

我试过这个:

IWorkItemDocument widoc = null;
try
{
    string tfsName = "http://rd-tfs-no2:8080/tfs/siproducts";
    var projectCollectionUri = new Uri(tfsName);

    var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(projectCollectionUri, new UICredentialsProvider());
    projectCollection.EnsureAuthenticated();
    DocumentService docService = (DocumentService)Package.GetGlobalService(typeof(DocumentService));
    widoc = docService.GetWorkItem(projectCollection, id,this);
    docService.ShowWorkItem(widoc);
}
finally
{
    widoc.Release(this);
}

但是帮助少了我获得docService的空值。

有什么好的建议吗?

3 个答案:

答案 0 :(得分:1)

Package仅在您使用Visual Studio插件时有效。如果您正在寻找显示工作项的方法,您可以通过将字段映射到winform / WPF应用程序,或者通过外壳到Internet Explorer并将工作项ID传递到基于Web的URL来实现。观看者。

答案 1 :(得分:0)

您可能想尝试查看TFS API中的WorkItemStore对象。

        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(Constants.TEAMFOUNDSERVER);
        WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
        string wiqlQuery = "SELECT [System.Id] FROM WorkItems";
        WorkItemCollection wic = workItemStore.Query(wiqlQuery);
        foreach (WorkItem wi in wic) 
        {
             //do work here
        }

答案 2 :(得分:0)

要获取文档服务,请尝试以下操作:

var dte2 = Marshal.GetActiveObject("VisualStudio.DTE.10.0") as DTE2;
var witDocumentService = (DocumentService)dte2.DTE.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService");