On how to get the collections from TFS refer here
Please refer here for more details. This is one of the best resources on TFS stuff.
The collection guid is passed in and the list returns the name of all projects in that particular collection.
public IList<string> GetProjectsFormCollection(Guid collectionId)
{
ICommonStructureService structureService = null;
try
{
TfsTeamProjectCollection teamProjectCollection =
_configurationServer.GetTeamProjectCollection(collectionId);
teamProjectCollection.Authenticate();
structureService =
(ICommonStructureService)teamProjectCollection.GetService(typeof(ICommonStructureService));
}
catch (Exception e)
{
ApplicationLogger.Log(e);
}
var projectInfoList = new List<ProjectInfo>(structureService.ListAllProjects());
IEnumerable<string> data = projectInfoList.Select(proj => proj.Name);
List<string> list = data.ToList();
return list;
}
you can do this now via the rest api. e.g.
GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects?api-version=1.0
from: https://www.visualstudio.com/en-us/docs/integrate/api/tfs/projects
来源:https://stackoverflow.com/questions/16101636/how-to-get-the-name-of-all-projects-in-a-tfs-collection