tags:

views:

198

answers:

3

Hi - 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 Project, but the problem is that people rename these IterationPaths as the projects progress, and the link is lost. So after some research, I'm thinking of doing the linking by using the IterationID. The IterationID in the TFSWarehouse is NOT the same as the IterationID in the WorkItemTracking table, and I can't seem to find an easy way to find the IterationID of an IterationPath? Anyone got any idea how we may be able to achieve this?

A: 

I'd use the powershell snap-in from the latest TFS Power Tools for this.

> $tfs = Get-TfsServer <name> -all
> $tfs.WIT.Projects | % { $_.IterationRootNodes } | ft -auto id, path

 Id Path                                       
 -- ----                                 
100 Test-ConchangoV2\Release 1\Sprint 1        
 92 Test-ConchangoV2\Release 1\Sprint 2        
 97 Test-ConchangoV2\Release 1\Sprint 3        
 91 Test-ConchangoV2\Release 1\Sprint 4        
 94 Test-ConchangoV2\Release 1\Sprint 5        
 93 Test-ConchangoV2\Release 1\Sprint 6        
 96 Test-ConchangoV2\Release 2\Sprint 1        
 90 Test-ConchangoV2\Release 2\Sprint 2        
 98 Test-ConchangoV2\Release 2\Sprint 3        
 99 Test-ConchangoV2\Release 3\Sprint 1        
 95 Test-ConchangoV2\Release 3\Sprint 2        
 89 Test-ConchangoV2\Release 3\Sprint 3
Richard Berg
Thanks - will download and take a look! If it can be done thru Powershell, there should be a way to do this thru the SDK? This linking tool is a ASP.NET application so would love to do in ASP.NET.
Kolchak
Had a play, and the above only shows Iteration that are 2 levels deep (eg Client Name\Root Iteration\Child Iteration). It doesn't show Root Iterations or Iterations that are children of children...
Kolchak
A: 

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);
                }
            }
        }

    }
}
Kolchak
A: 

if you want to print out all TFS Areas then change the following line:

from: NodeCollection rootNodeCollection = store.Projects[tfsProject].IterationRootNodes;

to: NodeCollection rootNodeCollection = store.Projects[tfsProject].AreaRootNodes;

thanks for the code it was helpfull at my end.