WIQL 查询以获取项目中的所有团队和用户?

WIQL query to get all the team and the users in a Project?

假设我有一个项目名称 ="Scrum" 并且该项目有一些用户并进行了冲刺,所以 **我想要 Scrum 中的 Sprint ** 项目的 dstinct 用户。附上图片。

根据您的描述,您似乎想要获取所有团队(包括团队中的所有用户)以及每个团队对应的sprint。

无法通过 WIQL 执行此操作。 WIQL 是一种工作项查询语言,用于查询错误、任务和其他类型的工作项。 return 值应该是工作项。

相反,您可以使用 Rest API 来实现您的要求。

1.First, Get a list of teams 在一个项目中。

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/eb6e4656-77fc-42a1-9181-4c6d8e9da5d1/teams?api-version=2.2

2.Get a team's members

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/eb6e4656-77fc-42a1-9181-4c6d8e9da5d1/teams/564e8204-a90b-4432-883b-d4363c6125ca/members/?api-version=2.2

3.Get a team's iterations

GET https://{instance}/DefaultCollection/{project}/{team}/_apis/work/TeamSettings/Iterations?[$timeframe=current&]api-version={version}

结合上面的 Rest APIs,你可以实现在 Scrum 项目和团队所有用户的 Sprints 中获取团队名称。

您也可以将此代码用于团队:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.ProcessConfiguration.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;

namespace QueryLinkedWIQL
{
    class Program
    {

        static List<TeamFoundationTeam> ListTeams(TfsTeamProjectCollection pTpc, Project pProject)
        {
            TfsTeamService _teamService = pTpc.GetService<TfsTeamService>();
            var _teams = _teamService.QueryTeams(pProject.Uri.ToString());

            return (from t in _teams select t).ToList();
        }

        static bool GetTeamsSettings(TfsTeamProjectCollection pTpc, TeamFoundationTeam pTeam)
        {
            try
            {
                var _teamConfig = pTpc.GetService<TeamSettingsConfigurationService>();

                var _configs = _teamConfig.GetTeamConfigurations(new Guid[] { pTeam.Identity.TeamFoundationId  });

                Console.WriteLine("============={0}==================", pTeam.Name);

                Console.WriteLine("Team Members: ");

                foreach (var _member in pTeam.GetMembers(pTpc, MembershipQuery.Expanded))
                    Console.WriteLine("Display Name: " + _member.DisplayName + " || Is active: " + _member.IsActive);

                foreach( var _config in _configs)
                {
                    Console.WriteLine("Team current iteration: " + _config.TeamSettings.CurrentIterationPath);
                    Console.WriteLine("Team selected iterations:");
                    foreach (var _iteration in _config.TeamSettings.IterationPaths)
                        Console.WriteLine(_iteration);
                    Console.WriteLine("Team selected areas:");
                    foreach (var _area in _config.TeamSettings.TeamFieldValues)
                        Console.WriteLine("Area path: " + _area.Value + " || Include children: " + _area.IncludeChildren.ToString());
                }

                Console.WriteLine("===============================");


            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }

        static void Main(string[] args)
        {

            string _teamProject = "YourProjectName";

            try
            {
                TfsTeamProjectCollection _tpc = new TfsTeamProjectCollection(new Uri("http://yourserver/DefaultCollection"));

                WorkItemStore _wistore = _tpc.GetService<WorkItemStore>();

                var _teams = ListTeams(_tpc, _wistore.Projects[_teamProject]);
                foreach (var _team in _teams) GetTeamsSettings(_tpc, _team);

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
    }
}