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

我想使用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的空值。

有什么好建议吗?

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

您可能想尝试查看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 } 

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

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