使用Powershell从TFS获取团队项目名称

时间:2015-10-02 16:51:10

标签: visual-studio powershell tfs

我需要在团队项目集合中生成团队项目名称列表。

有办法做到这一点吗?也许使用Powershell?

1 个答案:

答案 0 :(得分:2)

这是我使用的。可能有更好的方法,但这是有效的。这是将它绑定到下拉列表的方法。 C#

        Uri myUri = new Uri("https://tfs.mytfsserver.com/tfs");

        //    Get a TfsConfigurationServer instance

        TfsConfigurationServer configServer = TfsConfigurationServerFactory.GetConfigurationServer(myUri);
        configServer.EnsureAuthenticated();
        //    Get the CatalogNode that represents the hierarchy root
        CatalogNode rootNode = configServer.CatalogNode;

        //    Get the Team Project Collections that descend from the root node
        ReadOnlyCollection<CatalogNode> teamProjectCollections = rootNode.QueryChildren(
           new Guid[] { CatalogResourceTypes.ProjectCollection },
           false,
           CatalogQueryOptions.None);

        CatalogNode teamProjectCollection = teamProjectCollections[0];

        //    Get the Team Projects that belong to the Team Project Collection
        ReadOnlyCollection<CatalogNode> teamProjects = teamProjectCollection.QueryChildren(
           new Guid[] { CatalogResourceTypes.TeamProject },
           false,
           CatalogQueryOptions.None);


        ddl_TeamProjects.DataSource = teamProjects.Select(c => c.Resource.DisplayName).ToArray();
        ddl_TeamProjects.DataBind();