0
votes

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:

            tpc.Authenticate();

            // 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?

2
@Erik Philips.. why did you remove the TFS API prefix from the title? Without it, it's going to be hard for people to see this question in the right context :-(alejandrormz
Should questions include tags in the title - Stack Overflow has an extensive tag system which allows users to identify what technology is involved in a question, watch or ignore certain subjects, narrow their searches to a specific area, and even learn about the tag's subject via its wiki. This tag system works. You can rely on it to notify users who are interested in a tag about your question. Stack Overflow is optimized so that tags are indexed by search engines along with the content...Erik Philips

2 Answers

1
votes

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();
    Console.WriteLine(tconfig.TeamName);
    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};
    tscs.SetTeamSettings(tconfig.TeamId,ts);
0
votes

What you are looking for is TeamSettings Class, you can check case TFS 2012 API Set TeamSettings Programmatically of how to Set TeamSettings Programmatically:

 // Set up default team sprint date and time
        var teamConfig = _tfs.GetService<TeamSettingsConfigurationService>();
        var css = _tfs.GetService<ICommonStructureService4>();

        string rootNodePath = string.Format("\\{0}\\Iteration\\Release 1\\Sprint 1", _selectedTeamProject.Name);
        var pathRoot = css.GetNodeFromPath(rootNodePath);

        css.SetIterationDates(pathRoot.Uri, DateTime.Now.AddDays(-5), DateTime.Now.AddDays(7));

        var configs = teamConfig.GetTeamConfigurationsForUser(new[] { _selectedTeamProject.Uri });
        var team = configs.Where(c => c.TeamName == "Demo").FirstOrDefault();

        var ts = team.TeamSettings;
        ts.BacklogIterationPath = string.Format(@"{0}\Release 1", _selectedTeamProject.Name);
        ts.IterationPaths = new string[] { string.Format(@"{0}\Release 1\Sprint 1", _selectedTeamProject.Name), string.Format(@"{0}\Release 1\Sprint 2", _selectedTeamProject.Name) };

        var tfv = new TeamFieldValue();
        tfv.IncludeChildren = true;
        tfv.Value = _selectedTeamProject.Name;
        ts.TeamFieldValues = new []{tfv};

        teamConfig.SetTeamSettings(team.TeamId, ts);

Useful blog: http://blogs.microsoft.co.il/shair/2012/05/23/tfs-api-part-46-vs11-team-settings/