alejandrormz alejandrormz - 1 year ago 144
C# Question

How to set Backlog Iteration and Team/Area connection programmatically?

So far I can programmatically create a new Team and a new Area, but when I navigate to the TFS 2015 "Work" tab I see this error:

TF400509: No backlog iteration path was specified. You must select an iteration path.

So if I manually choose one iteration then I get:

TF400512: You have not selected any areas for your team. You must select at least one area before you can use features such as the product backlog, the task board or tiles.

Here's my code:


// Create New Area
ICommonStructureService css = tpc.GetService<ICommonStructureService>();
string rootNodePath = string.Format("\\Onboarding\\Area");
var pathRoot = css.GetNodeFromPath(rootNodePath);
var newAreaPath = css.CreateNode("Area 51", pathRoot.Uri);

// Create new Team with Same Name
TfsTeamService tts = tpc.GetService<TfsTeamService>();
string newteamname = "Area 51";
string teamdescription = "Area 51 Team Description";
IDictionary<string, object> prop = new Dictionary<string, object>
{"Area", "Area 51"},
{"Iteration", "\\Onboarding\\Iteration\\Onboarding" }
tts.CreateTeam(onboardingProject.Uri.ToString(), newteamname, teamdescription, prop);

TfsTeamService teamService = tpc.GetService<TfsTeamService>();
ProjectInfo projectInfo = css.GetProjectFromName("Onboarding");
var allTeams = teamService.QueryTeams(projectInfo.Uri);

So the question again?

At what point can you set the Backlog Iteration for the new Area, and how/where do you select the new Area for the new Team?

Answer Source

You can add following codes to set the backlog iteration path:

    TeamSettingsConfigurationService tscs = tpc.GetService<TeamSettingsConfigurationService>();
    IEnumerable<TeamFoundationTeam> teams = tts.QueryTeams(projectInfo.Uri);
    TeamFoundationTeam team = teams.Where(a => a.Name == "Area 51").FirstOrDefault();
    var teamconfigs = tscs.GetTeamConfigurations(new[] { team.Identity.TeamFoundationId });
    TeamConfiguration tconfig = teamconfigs.FirstOrDefault();
    TeamSettings ts = tconfig.TeamSettings;
    ts.IterationPaths = new string[] { string.Format("\\Onboarding\\Iteration 1") };
    ts.BacklogIterationPath = string.Format("\\Onboarding\\Iteration 1");
    TeamFieldValue tfv = new TeamFieldValue();
    tfv.IncludeChildren = true;
    tfv.Value = projectInfo.Name + "\\Area 51";
    ts.TeamFieldValues = new TeamFieldValue[] { tfv};