0

I am working on creating a team in TFS using C# and the dll's provided. I'm having a hard time setting the default Area and could use some help.

VssCredentials vc = new VssCredentials(true);
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(TFS_CONNECTION_URL), vc);
tpc.Authenticate();

TfsTeamService teamService = tpc.GetService<TfsTeamService>();
ProjectInfo projectInfo = cssService.GetProjectFromName(TEAM_PROJECT_NAME);
TeamFoundationTeam team = teamService.CreateTeam(projectInfo.Uri, teamName, teamDescription, null);
ICommonStructureService css = tpc.GetService<ICommonStructureService>();

foreach (NodeInfo ni in css.ListStructures(projectInfo.Uri))
{
    //ProjectModelHierarchy is for areas
    if (ni.StructureType.Equals("ProjectModelHierarchy"))
    {
        string n0Uri = ni.Uri;
        //creates the team name area under the top level team project area.
        string n1Uri = css.CreateNode(teamName, n0Uri);
    }
}

//AND HERE'S WHERE I WANT TO SET THE DEFAULT AREA
//I have tried the following but it doesn't work
//team.SetProperty("defaultArea", "\\" + teamName);

I have tried many combinations of the property name but to no avail. And I assure you, this code above does create a team in my team project in TFS.

InteXX
  • 6,135
  • 6
  • 43
  • 80

2 Answers2

0
var tfv = new TeamFieldValue();
var ts = team.TeamSettings;
tfv.IncludeChildren = true;
tfv.Value = "\\" + teamName;
ts.TeamFieldValues = new []{tfv};
AussieJoe
  • 1,285
  • 1
  • 14
  • 29
  • 1
    Is `ts` on the last line supposed to be `teamService`? – Chris Long Apr 04 '18 at 21:57
  • 1
    Thanks Chris, I was just about to ask that because teamService does not have any methods/properties of TeamFieldValues, so I'd appreciate an answer on this as well. – user9598761 Apr 05 '18 at 12:22
  • It's the WebApi field, however notice that I'm not using the WebApi structure. using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Framework.Client; using Microsoft.TeamFoundation.Server; using Microsoft.VisualStudio.Services.Common; – user9598761 Apr 05 '18 at 12:23
  • @ChrisLong yes, var ts = team.TeamSettings; – AussieJoe Apr 05 '18 at 16:09
  • Where are you getting your `team` instance for `team.TeamSettings`? I'm using the latest stable version of [the SDK](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Client), and I'm not finding it. Here's the [problem](https://stackoverflow.com/q/65472137/722393) I'm trying to solve. – InteXX Dec 28 '20 at 02:18
  • @InteXX look at the question, it is in there. – AussieJoe Dec 28 '20 at 16:08
  • Oops, I missed that—thank you. But... those APIs appear to be from an outdated version (`TfsTeamProjectCollection`, `TfsTeamService`, etc.). Do you know of any sample using the latest stable version? One would think that adding an Area to a Team should be a simple task, but unfortunately so far it's proving otherwise. – InteXX Dec 28 '20 at 20:09
0
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri("tfsuri"));
TfsTeamService teamService = ttpc.GetService<TfsTeamService>();
ICommonStructureService icss = ttpc.GetService<ICommonStructureService>();
ProjectInfo projectInfo = icss.GetProjectFromName("ProjectName");
var newteam = teamService.CreateTeam(projectInfo.Uri, "TeamName", null, null);
TeamSettingsConfigurationService tscs = ttpc.GetService<TeamSettingsConfigurationService>();
IEnumerable<Guid> teamsid = new Guid[] {newteam.Identity.TeamFoundationId };
var teamsconfig = tscs.GetTeamConfigurations(teamsid);
TeamConfiguration tc = teamsconfig.First();
TeamFieldValue tfv = new TeamFieldValue();
tfv.IncludeChildren = true;
tfv.Value = "AreaPath";
tc.TeamSettings.TeamFieldValues = new TeamFieldValue[] {tfv};
tc.TeamSettings.BacklogIterationPath = "IterationPath";
tscs.SetTeamSettings(tc.TeamId,tc.TeamSettings);  
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • Where are you getting these classes (`TfsTeamProjectCollection`, `TfsTeamService`, etc.)? I'm trying to add an existing Area to an existing Team (https://stackoverflow.com/q/65472137), but I'm not having much luck. Perhaps you can assist. – InteXX Dec 28 '20 at 02:02