Search code examples
c#tfsazure-devopstfs-sdk

Removing iteration in VSTS/TFS using Microsoft.TeamFoundation.Client


I use this code to create a new iteration on VSTS/TFS programatically:

var tfs = new TfsTeamProjectCollection(uri, tfsCredential);
var service = tfs.GetService<ICommonStructureService>();
var iterationRoot = service.GetNodeFromPath("\\TeamProjectName\\Iteration");
var iteration = service.CreateNode("Sprint 1", iterationRoot.Uri);

Now I want to remove an iteration but there is no corresponding method on ICommonStructureService. Oddly there is a method named GetDeletedNodesXml().


Solution

  • I got it! I'm assuming here that you have some method to retrieve an iteration.

    var tfs = new TfsTeamProjectCollection(uri, tfsCredential);
    var service = tfs.GetService<ICommonStructureService>();
    // TODO var iteration = GetIteration();    
    var projectInfo = service.GetProjectFromName(projectName)
    var nodes = service.ListStructures(projectInfo.Uri);
    service.DeleteBranches(iteration.Id, nodes[0].Uri);
    

    The key is to pass in Ids and not paths. TFS wants to retrieve artifact URLs which are represented as Ids. The second parameter of DeleteBranches is the artifact URL of the iteration-root which is obtained by calling ListStructures of the ICommonStructureService and taking the first element there (which is kind of nasty IMHO but I don't know a better way).