问题
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.
回答1:
var tfv = new TeamFieldValue();
var ts = team.TeamSettings;
tfv.IncludeChildren = true;
tfv.Value = "\\" + teamName;
ts.TeamFieldValues = new []{tfv};
回答2:
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);
来源:https://stackoverflow.com/questions/49659129/tfs-2017-c-set-default-area