Finding IterationID in TFS

前端 未结 4 553
不知归路
不知归路 2021-01-12 21:44

we are linking Iterations within TFS to an external system for tracking projects through the entire company. In the past, we were linking using the IterationPath in a TFS Pr

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 22:17

    OK - after some further digging, found the code below that iterates thru all the iterations, so using a subset of this, I will get what I needed :)

    using System;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.WorkItemTracking.Client;
    
    namespace TFSIterationList
    {
        class Program
        {
            static void Main(string[] args)
            {
                string tfsServer = "tfs";
                string tfsProject = "Project Name";
                TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsServer);
                WorkItemStore store = new WorkItemStore(tfsServer);
                PrintTreeNodeCount(store, tfsProject);
            }
    
    
            private static void PrintTreeNodeCount(WorkItemStore store, string tfsProject)
            {
                int iterationNodeCount = 0;
                NodeCollection rootNodeCollection = store.Projects[tfsProject].IterationRootNodes;
                GetChildNodeCount(rootNodeCollection, ref iterationNodeCount);
                Console.WriteLine(tfsProject + " Iteration nodes : " + iterationNodeCount);
             }
    
            private static void GetChildNodeCount(NodeCollection nodeCollection, ref int nodeCount)
            {
                nodeCount += nodeCollection.Count;
                for (int i = 0; i < nodeCollection.Count; i++)
                {
    
                    Console.WriteLine(nodeCollection[i].Id + " : " + nodeCollection[i].Path);
                    // Console.WriteLine(nodeCollection[i].Name);
    
                    if (nodeCollection[i].ChildNodes.Count > 0)
                    {  
                    // Recursively walk through the child nodes
                        GetChildNodeCount(nodeCollection[i].ChildNodes, ref nodeCount);
                    }
                }
            }
    
        }
    }
    

提交回复
热议问题