如何从TFS获取所有集合

时间:2013-04-19 09:03:26

标签: c# tfs tfs2012 alm

如何使用TFS API从TFS获取集合

有关详细信息,请参阅here。这是关于TFS的最佳资源之一。

1 个答案:

答案 0 :(得分:8)

private TfsConfigurationServer configurationServer;
configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(uri);



public IList<KeyValuePair<Guid, String>> GetCollections()
{
    //ApplicationLogger.Log("Entered into GetCollections() : ");
    var collectionList = new List<KeyValuePair<Guid, String>>();
    try
    {
        configurationServer.Authenticate();

        ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
            new[] { CatalogResourceTypes.ProjectCollection },
            false,
            CatalogQueryOptions.None);
        foreach (CatalogNode collectionNode in collectionNodes)
        {
            var collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection =
                configurationServer.GetTeamProjectCollection(collectionId);

            if (teamProjectCollection == null)
                continue;

            collectionList.Add(new KeyValuePair<Guid, String>(collectionId, teamProjectCollection.Name));
        }
    }
    catch (Exception e)
    {
        ApplicationLogger.Log(e);
    }

    return collectionList;
}

列表中每个返回的键值对都包含集合guid和集合名称