How to get the name of all projects in a TFS collection?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 16:29:06

问题


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.


回答1:


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;
}



回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!