我有一个 id,我想parentid
通过 C# 为 TFS 编码知道是否有一个。在我的 TFS 板上,有许多用户故事不包括Feature
?
我在 TFS 中的层次结构如下:
Feature
--->User Stories(u1,u2,u3)
--->Tasks (t1,t2,t3)
有时用户故事不包含Feature
我有一个 id,我想parentid
通过 C# 为 TFS 编码知道是否有一个。在我的 TFS 板上,有许多用户故事不包括Feature
?
我在 TFS 中的层次结构如下:
Feature
--->User Stories(u1,u2,u3)
--->Tasks (t1,t2,t3)
有时用户故事不包含Feature
您可以通过直接工作项查询获得此信息。您可以在 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);
}
}
}
============================for Relation Task->Something->Feature============
您可以使用树查询:
这个代码:
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);
}
}
}
---------屏幕
询问:
调试: