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

懵懂的女人 提交于 2019-12-06 02:45:24

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

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