Accessing Team Information using Team Foundation 11 SDK
Written against Visual Studio/Team Foundation beta; so subject to any changes in the SDK.
Team Foundation Server 11 has the notion of teams; and its possible to assign work and iterations to multiple teams within a single Team Project.
I was searching for a way to access the Team information via the Microsoft.TeamFoundation.Client API and stumbled over the TfsTeamService class.
Add a reference to Microsoft.TeamFoundation.Client.dll.
Note: The tfs assemblies can be found either in the GAC or under the folder %programfiles%\Microsoft Visual Studio 11.0\Common7\IDE
Create a connection to TFS project collection:
1Uri collectionUri = new Uri(@"http://<server>:8080/tfs/<tpcName>"); TfsTeamProjectCollection tfsConnection= new TfsTeamProjectCollection(collectionUri, new UICredentialsProvider());
Create an instance of the TfsTeamService class and call the Initialize method passing in the connection
1 TfsTeamService teamService = new TfsTeamService(); teamService.Initialize(tfsConnection);
You now must query the Team Information by calling a method on the TfsTeamService instance. There are 3 possible methods to use:
//The project URI - this is the identifier for the Team Project you're looking within.
1//To retrieve the project URI you need to iterate the team projects - see TFS 2010 on MSDN
string projectUri
1 = @"vstfs:///Classification/TeamProject/7356cf03-278b-4b04-8915-eb50d29665ca";
2```
3
4```
5//1. Returns the default team in the Team Project
TeamFoundationTeam defaultTeam = teamService.GetDefaultTeam(
1 projectUri,
new List<String>()
1 );
2```
3
4```
5//2. Returns a specific team in the Team Project based on the teamname parameter provided
TeamFoundationTeam specificTeam = teamService.ReadTeam(
1 projectUri,
"TeamName",
1 new List<String>()
);
//3. Returns all the teams in the Team Project
1IEnumerable<TeamFoundationTeam> allTeams = teamService.QueryTeams(projectUri);
2```
3```
4
5Now that you have the Team Information you can access it properties as expected. For example to console output a list of members in a team you can use:
6
7```
8TeamFoundationIdentity\[\] teamMembers= team.GetMembers(tfsConnection, MembershipQuery.Expanded); foreach (var member in teamMembers) { Console.WriteLine(" {0}", member.DisplayName); foreach (var item in member.GetProperties()) { Console.WriteLine(" {0}: {1}", item.Key, item.Value); } }
9```