Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically add new iteration in TFS

Tags:

c#

tfs

tfs-sdk

I can manually add a new iteration to a team project in TFS by right clicking on the project and going to Team Project Settings > Areas and Iterations > Iterations tab.

Is there an example out there of how to do this programmatically using their API?

Thanks!

like image 481
J Cooper Avatar asked Apr 25 '11 21:04

J Cooper


People also ask

How do I create a new iteration?

To create an iteration type, click Manage in the Iteration Type field; click the Create a New Iteration Type icon; enter an ID and display name; and click OK. The new iteration type is displayed in the Iteration Type field. Click the calendar icon next to the Start date or End date to specify a date.

How do I add sprints to Ado?

To do this, go to Project Settings > Team Configuration, and go to the Iterations tab. Use Select Iteration(s) (or Sprints), to add the sprints that you want to display on the board.


2 Answers

After some experimentation based on taylonr's link, here's what I came up with as a minimal solution for adding an iteration, in case any one else runs into this:

    public void AddIteration(string projectName, string iterationName)
    {
        using (var tfsCollection = new TfsTeamProjectCollection(new Uri(tfsServerUrl), getTfsCredentials()))
        {
            tfsCollection.Authenticate();
            var css = tfsCollection.GetService<ICommonStructureService>();
            string rootNodePath = string.Format("\\{0}\\Iteration", projectName);
            var pathRoot = css.GetNodeFromPath(rootNodePath);
            css.CreateNode(iterationName, pathRoot.Uri);
        }
    }
like image 102
J Cooper Avatar answered Sep 30 '22 15:09

J Cooper


Does this tutorial solve your problem? http://blogs.microsoft.co.il/blogs/shair/archive/2009/01/30/tfs-api-part-10-add-area-iteration-programmatically.aspx

Google-Fu "tfs api add iteration"

From glancing at his code, (and using TFS) it looks like iterations are getting treated as hierarchies. That's why you see things like "Release1\Sprint2" etc... you can have them nested deep... deep down they're probably just a path and that's why he's using the add path etc

like image 25
taylonr Avatar answered Sep 30 '22 15:09

taylonr