C#获取每个工作项的TFS看板板栏

时间:2017-02-03 02:48:52

标签: c# tfs workitem kanban

我有我的WorkItemStore集合。我需要在其中的每个WorkItem上执行操作。当我正在迭代时,我需要获得它所在的BoardColumn。非常简单,但我很难弄清楚如何让WorkItem告诉我它的BoardColumn。

        // Get our WorkItem Store
        TfsTeamProjectCollection projectCollection = GetTfsProjectCollection(tfsCollectionUri);
        WorkItemStore workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));

        // Run a query for all Tasks on the "New Creative Work" Board.
        WorkItemCollection queryResults = workItemStore.Query(
            "Select [State], [Title] " +
            "From WorkItems " +
            "Where[System.AreaPath] = '<MySysAreaPath>' " +
            "AND[System.BoardLane] = '<MyBoardLane>'" +
            "AND[System.State] Does Not Contain 'Completed'");

        foreach(WorkItem item in queryResults)
        {
            string myBoardColumn = item[DO NOT KNOW WHAT GOES HERE]...
            //DO Stuff > Update db record
        }

非常感谢任何帮助!!!!

1 个答案:

答案 0 :(得分:2)

最简单的方法是将TFS升级到TFS 2015 Update 1及更高版本,如在TFS 2015.1及更高版本中,已在工作项查询中启用Board Column字段。您可以在工作项查询中轻松查询和显示看板字段。

要查询查询中每个工作项的TFS Board Column字段,请参阅下面的代码段:

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

namespace GetWorkItemField
{
    class Program
    {
        static void Main(string[] args)
        {
            var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsserver:8080/tfs/teamprojectcollection"));
            var service = tfs.GetService<WorkItemStore>();
            string workItemQueryString = "Select Id, Title From WorkItems Where [System.TeamProject] = 'TeamProject'";
            var workItemQuery = new Query(service, workItemQueryString);
            WorkItemCollection queryResults = workItemQuery.RunQuery();

            foreach (WorkItem item in queryResults)
            {
                var t = item.Fields["System.BoardColumn"];
                Console.WriteLine("{0}: {1}", item.Title, t.Value);
            }

        }
    }
}