【问题标题】:Azure Devops, how to get all shared query of my project - Powershell or C#Azure Devops,如何获取我的项目的所有共享查询 - Powershell 或 C#
【发布时间】:2020-11-04 18:24:21
【问题描述】:

我们正在使用 TFS19 更新 1。

我们添加了一个新字段,并且我们想要更改之前使用旧字段的所有查询,以使用这个新字段。

为此,首先我们需要找到所有使用旧字段的查询,然后手动或使用 other-script/continues-script 进行更改。

如何找到所有查询 wiql?

尝试使用Rest Api get方法:

http://tfs19-app-test:8080/tfs/CollectionName/ProjectName/_apis/wit/queries?$expand=all&$depth=2&api-version=5.0

我只收到一小部分查询,我们在文件夹中有很多文件夹...

【问题讨论】:

  • 你检查过下面的答案了吗?如果它对您有帮助,您可以Accept it as an Answer,这对阅读此主题的其他社区成员会有所帮助。

标签: tfs azure-devops azure-devops-rest-api azure-devops-server-2019


【解决方案1】:

当您运行 API 时:

http://tfs19-app-test:8080/tfs/CollectionName/ProjectName/_apis/wit/queries?$expand=all&$depth=2&api-version=5.0

你得到一个只有 2 个值的小响应:

  1. 共享查询

  2. 我的查询

然后您需要检查它们的children 属性。如果孩子是查询- 好。如果是文件夹,您将看到另一个 children 属性,但现在没有完整结果,您需要执行 Queries - Get API 来获取此特定文件夹,然后检查 childern

$url = "http://tfs19-app-test:8080/tfs/CollectionName/ProjectName/_apis/wit/queries?$expand=all&$depth=2&api-version=5.0"

$repsonse = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -UseDefaultCredentials

# The $repsonse.value is array of 2 types. $repsonse.value.name:
# - Shared Queries
# - My Queries

# $repsonse.value[0].children = all the quries inside the Shared Queries
# Now iterate the value and check if you see `hasChildren` = True, if yes call the get query api

【讨论】:

    【解决方案2】:

    示例:

    static void GetQueryClientAPI()
            {
                VssCredentials Credentials = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "Personal access token"));
                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("TFS URL"), Credentials);
                tpc.EnsureAuthenticated();
                Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore wis = tpc.GetService(typeof(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore)) as Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore;
                Microsoft.TeamFoundation.WorkItemTracking.Client.QueryHierarchy qh = wis.Projects["Demo"].QueryHierarchy;
                foreach (Microsoft.TeamFoundation.WorkItemTracking.Client.QueryItem q in qh)
                {
                    GetChildQuery(q);
                }
                Console.Read();
            }
            static void GetChildQuery(Microsoft.TeamFoundation.WorkItemTracking.Client.QueryItem query)
            {
    
                if (query is Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder)
                {
                    Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder queryFolder = query as Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder;
                    foreach (var q in queryFolder)
                    {
                        GetChildQuery(q);
                    }
                }
                else
                {
                    Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition querydef = query as Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition;
                    Console.WriteLine(querydef.Name + " -- " + querydef.Path);
                }
            }
    

    包裹:Microsoft.TeamFoundationServer.ExtendedClient

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 2015-08-28
      • 2021-04-19
      • 2021-01-11
      • 1970-01-01
      • 2020-11-11
      • 2020-07-22
      • 2020-01-18
      相关资源
      最近更新 更多