TFS SDK 2013获取给定团队项目中的团队名称

时间:2014-07-17 20:17:53

标签: c# tfs tfs-sdk

你好,有人可以帮助我让所有团队参与一个特定的团队项目。

当前代码获取所有团队项目(来自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();
    } 

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

1 个答案:

答案 0 :(得分:2)

在codeplex上检查ALM Rangers上的TFS Team Tools的源代码。 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();
}