鏈接到您的Bug的任何工作項都被視爲RelatedLink
。請檢查here,以獲取Link
派生的可用類型,以及@bryanmac的SO-post this。
隨着你應該能夠檢索您的bug各相關工作項目的類型如下123456
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace WorkItemLinksOfAWorkItem
{
class Program
{
static void Main()
{
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSURI"));
var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
var workItem = workItemStore.GetWorkItem(123456);
LinkCollection links = workItem.Links;
foreach (Link link in links)
{
if (!(link is RelatedLink))
continue;
var relLink = link as RelatedLink;
var relatedWI = workItemStore.GetWorkItem(relLink.RelatedWorkItemId);
Console.WriteLine(relatedWI.Id+" "+relatedWI.Type.Name);
}
}
}
}
(本來我發現這些來源中Scrum Dashboard基)
爲了生成你的bug 123456新的測試用例,你可以嘗試像:
var workItemTypes = workItemStore.Projects["TeamProjectName"].WorkItemTypes;
var workItem = new WorkItem(workItemTypes["Test Case"]) {Title = "Programmatically constructed via TFS-SDK"};
var relatedLinkToBug = new RelatedLink(123456);
var links = workItem.Links;
links.Add(relatedLinkToBug);
workItem.Save();
很不錯的答案。 – 2012-07-25 18:28:16