2014-07-17 121 views
1

您好可以有人请帮助我获得给定团队项目中的所有团队。TFS SDK 2013在给定的团队项目中获取团队名称

当前的代码所有团队项目(从http://msdn.microsoft.com/en-us/library/bb286958.aspx

public void getTeamProjects() 
    { 
     TfsConfigurationServer configServer = TfsConfigurationServerFactory.GetConfigurationServer(_uri); 
     ReadOnlyCollection<CatalogNode> collectionNodes = configServer.CatalogNode.QueryChildren(
      new[] { CatalogResourceTypes.ProjectCollection }, 
      false, CatalogQueryOptions.None); 

     foreach (CatalogNode collectionNode in collectionNodes) 
     { 
      Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); 
      TfsTeamProjectCollection teamProjectCollection = configServer.GetTeamProjectCollection(collectionId); 
      Console.WriteLine("Collection: " + teamProjectCollection.Name); 

      ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
      new[] { CatalogResourceTypes.TeamProject }, 
      false, CatalogQueryOptions.None); 

      foreach (CatalogNode projectNode in projectNodes) 
      { 
       Console.WriteLine("Team Project: " + projectNode.Resource.DisplayName); 
       // How do I access the Team names of each projectNode. 
      } 

     } 

     Console.WriteLine("Finished"); 
     Console.ReadKey(); 
    } 

目前,它被正确地打印出所有的团队项目的控制台上。我希望能够访问每个团队项目中的团队名称。

回答

2

从codeplex上的ALM Rangers中检查TFS团队工具的源代码。 The ListTeams method does exactly what you're after

this.teamService = this.teamProjectCollection.GetService<TfsTeamService>(); 

public List<string> ListTeams() 
{ 
    var teams = this.teamService.QueryTeams(this.projectInfo.Uri); 
    return (from t in teams select t.Name).ToList(); 
}