【问题标题】:How to know if a ID has a parent ID or not in WIQL TFS?如何知道一个 ID 在 WIQL TFS 中是否有父 ID?
【发布时间】:2018-02-20 10:22:14
【问题描述】:

我有一个 id,我想知道是否有一个 parentid,通过 C# 编码为 TFS。在我的 TFS 板上,有许多用户故事不包含 Feature ?

我在 TFS 中的层次结构如下:

Feature
--->User Stories(u1,u2,u3)
--->Tasks (t1,t2,t3)

有时用户故事不包含Feature

【问题讨论】:

标签: c# tfs azure-devops wiql


【解决方案1】:

您可以通过直接工作项查询来获得此信息。您可以在 VS 中创建它并保存到本地驱动器:

然后您可能会在已保存的查询中找到查询文本:

<?xml version="1.0" encoding="utf-8"?><WorkItemQuery Version="1"><TeamFoundationServer>http://myserverandcollection</TeamFoundationServer><TeamProject>MyProject</TeamProject><Wiql>
SELECT [System.Id], [System.Links.LinkType], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItemLinks WHERE ([Source].[System.Id] = 174) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse') And ([Target].[System.WorkItemType] = 'Feature') ORDER BY [System.Id] mode(MustContain)
</Wiql></WorkItemQuery>

然后您可以使用 Microsoft.TeamFoundationServer.ExtendedClient nugate 包创建应用程序

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://myserver/myCollection");

            int _id = 175;
            string _wiql = String.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.Id] = {0}) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse') And ([Target].[System.WorkItemType] = 'Feature') ORDER BY [System.Id] mode(MustContain)", _id);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            if (_links.Count() == 2) //only 1 child and its parent
                Console.WriteLine("Parent ID: " + _links[1].TargetId);
            else
                Console.WriteLine("There is no parent for ID: " + _id);
        }
    }
}

===========================关系任务->某事->功能=========== =

您可以使用树查询:

还有这段代码:

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://myserver/myCollection");

            int _id = 210;
            string _wiql = String.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.WorkItemType] = 'Feature') And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And ([Target].[System.Id] = {0}  AND  [Target].[System.WorkItemType] = 'Task') ORDER BY [System.Id] mode(Recursive,ReturnMatchingChildren)", _id);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            if (_links.Count() > 1) //first item contains feature
                Console.WriteLine("Parent ID: " + _links[0].TargetId);
            else
                Console.WriteLine("There is no parent for ID: " + _id);
        }
    }
}

---------屏幕

查询:

调试:

【讨论】:

  • 我可以知道一个任务是否有一个特征 ID 吗?
  • 此示例使用任何具有已知 ID (int _id = 175;) 的工作项类型(任务、用户故事、错误)来查找其父功能 ID。 “_links[1].TargetId”包含功能 ID。
  • 我要查找任务 featureid
  • 这是在我的 vsts 帐户上进行的测试,屏幕已添加到主答案中。
  • 你能帮我解决这个问题吗stackoverflow.com/questions/48921922/…
猜你喜欢
  • 1970-01-01
  • 2017-09-12
  • 1970-01-01
  • 2016-07-05
  • 2019-03-17
  • 1970-01-01
  • 2018-12-08
  • 1970-01-01
  • 2017-06-10
相关资源
最近更新 更多