在TFS 2012中获得“子项目”(团队?)

时间:2013-06-24 20:59:17

标签: c# tfs tfs2012

Similar to this,我想让用户下列出所有项目。我目前正在使用链接中的代码:

private static List<string> GetTfsProjects(Uri tpcAddress)
{
    var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcAddress);

    tpc.Authenticate();

    var workItemStore = new WorkItemStore(tpc);
    var projectList = (from Project pr in workItemStore.Projects select pr.Name).ToList();

    return projectList;
}

..但它只返回“LSWebsite”(我的URI是h ttp://server:port/defaultcollection)。我如何获得LSWebsite及其子女?下图显示了我目前正在使用的层次结构。

Sample hierarchy image

1 个答案:

答案 0 :(得分:2)

那些看起来像团队。

试试这个代码段:

var teamService = tpc.GetService<TfsTeamService>();

var teams =
        projectList
        .SelectMany(
            projectId =>
                teamService
                .QueryTeams(projectId)
                .Select(t =>  String.Format("{0}\\{1}", projectId, t.Name)))
        .ToArray();

projectList.AddRange(teams);

取自Shai的博客here

相关问题