I want to open the workitem from outside visual studio using C# code. is it possible?
I tried with this :
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.Ensur开发者_如何学运维eAuthenticated();
DocumentService docService = (DocumentService)Package.GetGlobalService(typeof(DocumentService));
widoc = docService.GetWorkItem(projectCollection, id,this);
docService.ShowWorkItem(widoc);
}
finally
{
widoc.Release(this);
}
But help less Im getting null value for docService.
Any good suggestion?
The Package
only works when you are working on a Visual Studio plug-in. If you're looking for a way to display the work item, you could either do it by mapping fields to your winform/WPF application, or by shelling out to Internet Explorer and passing the work item ID into the URL for the web-based viewer.
You may want to try looking at the WorkItemStore object in the TFS API.
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
}
To get the document service, try this:
var dte2 = Marshal.GetActiveObject("VisualStudio.DTE.10.0") as DTE2;
var witDocumentService = (DocumentService)dte2.DTE.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService");
精彩评论