我有使用TFS API檢索工作項目及其所有鏈接工作項目(代碼如下)的工作代碼(感謝John Socha-Leialoha)。但是,我想要做的是訪問鏈接文件的名稱(TFS稱它爲「Versioned Item」),以供每個工作項目使用。在TFS GUI中,您可以將文件鏈接到工作項目。說工作項目1234鏈接到文件foo.txt。現在,當我運行此查詢來查找鏈接項時,該文件不在列表中 - 僅返回其他子WI或父WI。如果我在GUI中完全創建和運行查詢,結果是一樣的。我怎樣才能找出哪些文件鏈接到給定的WI?我現在唯一的方法是在TFS GUI中查看WI,並在右下角的Files列表中顯示。如何從TFS檢索鏈接的「版本控制的項目」
也許我只是需要做一個正常的平面查詢,獲取WI領域,不知何故鏈接文件的名稱將是該WI的領域之一?我不需要下載鏈接的文件,我只需要文件名/位置。
代碼返回所有鏈接的是突,在這裏:
public List<string> GetLinkedItems()
{
//executes a linked item query, returning work items, as well as the items that are link to them.
//gets digital asset work item that contains the given part number in the Assoc. Parts field
var result = new List<string>();
var tpc = new TfsTeamProjectCollection(new Uri(_tfsUri));
var workItemStore = (WorkItemStore) tpc.GetService(typeof (WorkItemStore));
//and [Schilling.TFS.TechPub.AssocParts] CONTAINS '101-4108'
var query =
"SELECT [System.Id], [System.Links.LinkType], [System.TeamProject]," +
" [System.WorkItemType], [System.Title], [System.AssignedTo]," +
" [System.State] FROM WorkItemLinks " +
" WHERE ([Source].[System.TeamProject] = 'Tech Pubs' AND " +
" [Source].[System.WorkItemType] = 'DigitalAsset' AND " +
" [Source].[System.State] <> '') And " +
" ([System.Links.LinkType] <> '') And " +
" ([Target].[System.WorkItemType] <> '') " +
" ORDER BY [System.Id] mode(MayContain)";
var treeQuery = new Query(workItemStore, query);
//Note we need to call RunLinkQuery here, not RunQuery, because we are doing a link item type of query
var links = treeQuery.RunLinkQuery();
//// Build the list of work items for which we want to retrieve more information//
int[] ids = (from WorkItemLinkInfo info in links
select info.TargetId).Distinct().ToArray();
//
// Next we want to create a new query that will retrieve all the column values from the original query, for
// each of the work item IDs returned by the original query.
//
var detailsWiql = new StringBuilder();
detailsWiql.AppendLine("SELECT");
bool first = true;
foreach (FieldDefinition field in treeQuery.DisplayFieldList)
{
detailsWiql.Append(" ");
if (!first)
detailsWiql.Append(",");
detailsWiql.AppendLine("[" + field.ReferenceName + "]");
first = false;
}
detailsWiql.AppendLine("FROM WorkItems");
//
// Get the work item details
//
var flatQuery = new Query(workItemStore, detailsWiql.ToString(), ids);
WorkItemCollection details = flatQuery.RunQuery();
return
(from WorkItem wi in details
select wi.Id + ", " + wi.Project.Name + ", " + wi.Title + ", " + wi.State).ToList();
}
從這段代碼你如何知道誰是孩子的父母? – 2018-02-16 06:20:12