我正在尝试使用以下 REST 调用 https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/queries/list?view=azure-devops获取项目下的所有可用查询-rest-5.0#uri-parameters
如果不仅返回第一级查询并且深度的最大允许值似乎是 2 ,则需要传递深度参数。
如果我在查询中有 3 级文件夹结构,即使这个深度也无济于事。
那么如何检索所有查询而不考虑级别?
TIA
我正在尝试使用以下 REST 调用 https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/queries/list?view=azure-devops获取项目下的所有可用查询-rest-5.0#uri-parameters
如果不仅返回第一级查询并且深度的最大允许值似乎是 2 ,则需要传递深度参数。
如果我在查询中有 3 级文件夹结构,即使这个深度也无济于事。
那么如何检索所有查询而不考虑级别?
TIA
作为解决方法,您可以使用Microsoft.TeamFoundationServer.Client并探索深度为 1 的查询结构。示例:
static void GetAllWorkItemQueries(string project)
{
List<QueryHierarchyItem> rootQueries = WitClient.GetQueriesAsync(project, QueryExpand.All).Result;
GetFolderContent(project, rootQueries);
}
/// <summary>
/// Get Content from Query Folders
/// </summary>
/// <param name="project">Team Project Name</param>
/// <param name="queries">Folder List</param>
static void GetFolderContent(string project, List<QueryHierarchyItem> queries)
{
foreach(QueryHierarchyItem query in queries)
{
if (query.IsFolder != null && (bool)query.IsFolder)
{
Console.WriteLine("Folder: " + query.Path);
if ((bool)query.HasChildren)
{
QueryHierarchyItem detiledQuery = WitClient.GetQueryAsync(project, query.Path, QueryExpand.All, 1).Result;
GetFolderContent(project, detiledQuery.Children.ToList());
}
}
else
Console.WriteLine("Query: " + query.Path);
}
}
此处的完整示例项目:https ://github.com/ashamrai/TFResApi/tree/master/04.TFRestApiAppWorkItemQueries
您也可以使用客户端 API 来完成,简单的代码:
static void GetQueryClientAPI()
{
VssCredentials Credentials = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "Personal access token"));
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("devops url"), Credentials);
tpc.EnsureAuthenticated();
WorkItemStore wis = tpc.GetService(typeof(WorkItemStore)) as WorkItemStore;
QueryHierarchy qh = wis.Projects["project name"].QueryHierarchy;
foreach(QueryItem q in qh)
{
GetChildQuery(q);
}
Console.Read();
}
static void GetChildQuery(QueryItem query)
{
if (query is QueryFolder)
{
QueryFolder queryFolder = query as QueryFolder;
foreach (var q in queryFolder)
{
GetChildQuery(q);
}
}
else
{
QueryDefinition querydef = query as QueryDefinition;
Console.WriteLine(querydef.Name + " -- " + querydef.Path);
}
}
结果: