如何通过 WIQL C# 代码在 TFS 中查找所有 Sprint 的错误、功能、任务?

how to find all the Sprint's bugs,Feature,Task work in TFS by WIQL C# code?

我想找到查询以找到所有 bugs,Task,Feature,Stories 我团队的所有冲刺。
我的项目名称“MRI_Scrum_GIt”中有 2 个团队,其中包含 2 个团队 Phoneix 和 SS,这两个团队包含 Respected sprints (正在进行或完成)
以及如何让所有团队都参与到项目(查询)中,在我的案例中,SS 和 MRI_Scrum

的 phoniex

我用组操作而不是操作创建了查询 "In":

对于我的项目,保存查询中的 wiql 是:

SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = 'VSTSScrum' AND ( [Source].[System.WorkItemType] = 'Bug' OR [Source].[System.WorkItemType] = 'Product Backlog Item' OR [Source].[System.WorkItemType] = 'Feature' ) AND ( [Source].[System.IterationPath] UNDER 'VSTSScrum\SS' OR [Source].[System.IterationPath] UNDER 'VSTSScrum\Phoneix' )) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And ([Target].[System.WorkItemType] = 'Task' OR [Target].[System.WorkItemType] = 'Product Backlog Item') ORDER BY [System.Id] mode(Recursive)

您请求的源代码:

using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryLinkedWIQL
{
    class Program
    {
        static void Main(string[] args)
        {
            WorkItemStore _wistore = new WorkItemStore("http://server/collection");

            string _teamProject = "VSTSScrum";
            string _teamPhoneixRootIteration = "VSTSScrum\Phoneix";
            string _teamSSRootIteration = "VSTSScrum\SS";

                string _wiql = string.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = '{0}'"+ 
                "AND ( [Source].[System.WorkItemType] = 'Bug'  OR  [Source].[System.WorkItemType] = 'Product Backlog Item'  OR  [Source].[System.WorkItemType] = 'Feature' ) " + 
                "AND ( [Source].[System.IterationPath] UNDER '{1}'  OR  [Source].[System.IterationPath] UNDER '{2}' )) " + 
                "And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And " + 
                "([Target].[System.WorkItemType] = 'Task'  OR  [Target].[System.WorkItemType] = 'Product Backlog Item') ORDER BY [System.Id] mode(Recursive)",
                _teamProject, _teamPhoneixRootIteration, _teamSSRootIteration);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            foreach(WorkItemLinkInfo _link in _links)
            {
                //process link info item ....
            }
        }
    }
}

==============================

如果您不了解您所有的团队。你可以在这里找到它们:Add teams and team members

在这种情况下,您的所有团队都必须有默认迭代 "ProjectName\IterationName"。

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryLinkedWIQL
{
    class Program
    {
        static List<string> ListTeams(TfsTeamProjectCollection pTpc, Project pProject)
        {
            TfsTeamService _teamService = pTpc.GetService<TfsTeamService>();
            var _teams = _teamService.QueryTeams(pProject.Uri.ToString());
            return (from t in _teams select t.Name).ToList();
        }

        static string ConstructTeamsString(string pProjectName, List<string> pTeamNames)
        {
            string _val = "";

            for(int  i = 0; i< pTeamNames.Count; i++)
                if (pTeamNames[i] == "SS" || pTeamNames[i] == "Phoneix") // I have many teams without iteration root name. So I use this if to remove unneeded teams. You can remove this line
                    _val += ((_val != "") ? " OR " : "") + string.Format("[Source].[System.IterationPath] UNDER '{0}\{1}'", pProjectName, pTeamNames[i]);

            return _val;
        }

        static void Main(string[] args)
        {
            string _teamProject = "VSTSScrum";

            TfsTeamProjectCollection _tpc = new TfsTeamProjectCollection(new Uri("http://server/collection"));

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

            string _teamsStr = ConstructTeamsString(_teamProject, ListTeams(_tpc, _wistore.Projects[_teamProject]));

            string _wiql = string.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = '{0}'"+ 
                "AND ( [Source].[System.WorkItemType] = 'Bug'  OR  [Source].[System.WorkItemType] = 'Product Backlog Item'  OR  [Source].[System.WorkItemType] = 'Feature' ) " + 
                "AND ( {1} )) " + 
                "And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And " + 
                "([Target].[System.WorkItemType] = 'Task'  OR  [Target].[System.WorkItemType] = 'Product Backlog Item') ORDER BY [System.Id] mode(Recursive)",
                _teamProject, _teamsStr);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            foreach(WorkItemLinkInfo _link in _links)
            {
                //process link info item ....
            }
        }
    }
}