如何使用TFS API从TFS获取集合
有关详细信息,请参阅here。这是关于TFS的最佳资源之一。
答案 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和集合名称