Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 要使用C根据Azure DevOps中workitem类型功能的功能标题获取功能详细信息吗_C#_Azure Devops_Azure Devops Rest Api_Tfs Sdk - Fatal编程技术网

C# 要使用C根据Azure DevOps中workitem类型功能的功能标题获取功能详细信息吗

C# 要使用C根据Azure DevOps中workitem类型功能的功能标题获取功能详细信息吗,c#,azure-devops,azure-devops-rest-api,tfs-sdk,C#,Azure Devops,Azure Devops Rest Api,Tfs Sdk,我正在尝试开发一个控制台应用程序,以获取Azure DevOps中workitem类型功能的workitem详细信息 我想获取功能id、状态等详细信息。功能的标题将包含需求编号和需求名称,我将知道功能标题中的需求编号,并希望获取功能id(如果存在) 我将这些Nuget包用于我的代码: Microsoft.TeamFoundation.WorkItemTracking.WebApi; Microsoft.VisualStudio.Services.WebApi; 首先,您必须连接到服务wit并获

我正在尝试开发一个控制台应用程序,以获取Azure DevOps中workitem类型功能的workitem详细信息

我想获取功能id、状态等详细信息。功能的标题将包含需求编号和需求名称,我将知道功能标题中的需求编号,并希望获取功能id(如果存在)

我将这些Nuget包用于我的代码:

Microsoft.TeamFoundation.WorkItemTracking.WebApi;
Microsoft.VisualStudio.Services.WebApi;

首先,您必须连接到服务wit并获取工作项客户端:

VssConnection connection = new VssConnection(new Uri(ServiceURL), new VssBasicCredential(string.Empty, PAT));
WitClient = connection.GetClient<WorkItemTrackingHttpClient>();
如果试图通过标题内容查找工作项,可以使用wiql查询:

string queryWiqlList = @"SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = 'TEAM_PROJECT_NAME' and [System.Title] Contains '<YOUR SEARCH_TEXT>' and [System.State] <> 'Removed' and [System.State] <> 'Closed'";

Wiql wiql = new Wiql();
wiql.Query = wiqlStr;
WorkItemQueryResult result = WitClient.QueryByWiqlAsync(wiql).Result;

if (result != null)
{
    if (result.WorkItems != null) // this is Flat List 
        foreach (var wiRef in result.WorkItems)
        {
            var wi = WitClient.GetWorkItemAsync(wiRef.Id).Result;
            Console.WriteLine(String.Format("{0} - {1}", wi.Id, wi.Fields["System.Title"].ToString()));
        }
}

@BSS接受我的回答。也许有人也会发现它很有用。
string queryWiqlList = @"SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = 'TEAM_PROJECT_NAME' and [System.Title] Contains '<YOUR SEARCH_TEXT>' and [System.State] <> 'Removed' and [System.State] <> 'Closed'";

Wiql wiql = new Wiql();
wiql.Query = wiqlStr;
WorkItemQueryResult result = WitClient.QueryByWiqlAsync(wiql).Result;

if (result != null)
{
    if (result.WorkItems != null) // this is Flat List 
        foreach (var wiRef in result.WorkItems)
        {
            var wi = WitClient.GetWorkItemAsync(wiRef.Id).Result;
            Console.WriteLine(String.Format("{0} - {1}", wi.Id, wi.Fields["System.Title"].ToString()));
        }
}