使用TFS API查找哪些WorkItem是代码评论

时间:2017-05-19 16:34:50

标签: c# visual-studio-2015 tfs tfs2015

鉴于WorkItems列表,我想在C#中使用TFS 2015 API找到与Code Review对应的实例。

虽然我可以从描述的文本中看到WorkItem是否是Code Review,但我更愿意避免解析该字符串并依赖更强大的东西(例如:WorkItem.Type)......

你会怎么做(类型值对我来说似乎很神秘)?

1 个答案:

答案 0 :(得分:2)

您可以使用以下方法获取工作项的类型。但是你需要提供workitem id。

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

        Uri collectionUri = (args.Length < 1) ?
            new Uri("http://servername:8080/tfs/MyCollection") : new Uri(args[0]);

        // Connect to the server and the store. 
        TfsTeamProjectCollection teamProjectCollection =
           new TfsTeamProjectCollection(collectionUri);

         WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
        string queryString = "Select [State], [Title],[Description] From WorkItems Where [Work Item Type] = 'Code Review Request' or [Work Item Type] = 'Code Review Response'";

        // Create and run the query.
        Query query = new Query(workItemStore, queryString);
        WorkItemCollection witCollection = query.RunQuery();

        foreach (WorkItem workItem in witCollection)
        {
            workItem.Open();
            Console.WriteLine(workItem.Fields["Title"].Value.ToString());

        }