c# - 通过 Visual Studio Team Services 和 Team Foundation Server 的 REST API 概述从 Microsoft vso WorkItem 访问评论

标签 c# asp.net tfs azure-devops workitem

所以这里是我将从 Visual Studio Team Services 获取评论的地方,通过从 VSO 传递工作项的 ID,我应该能够从任何给定的工作项中提取评论历史记录,因为我将“id”传递给GetCommentsAsync 我得到一个空的评论结果,即使我给 api 的 workItem id 确实有评论。

 public WorkItemComments GetPageOfWorkItemComments(string VSTSID)
    {
        int id = Int32.Parse(VSTSID);
        VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);
        VssConnection connection = new VssConnection(new Uri(_uri), credentials);
        WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();

        WorkItemComments result = workItemTrackingClient.GetCommentsAsync(id).Result;

        Console.WriteLine("Total Revision Count: {0}", result.TotalCount);
        Console.WriteLine("From Revision Count: {0}", result.FromRevisionCount);
        Console.WriteLine("Comments...");

        foreach (var comments in result.Comments)
        {
            Console.WriteLine("{0}", comments.Text);
            Console.WriteLine();
        }
        return result;
    }

当我的代码开始查看注释结果并抛出错误时,它在 foreach 上中断:未将对象引用设置为对象的实例。

从这里开始我的通话:

    public string CreateWorkItem(string title, string description, string 
     PTID, string assigned, string VSTSID)
    {
        Response response;
        VssObject work = new VssObject();
        try
        {
            //work.CreateWIUsingClientLib(title, description, PTID, 
        assigned, VSTSID);
             //work.GetWorkItemById(PTID);
            work.GetPageOfWorkItemComments(VSTSID);
            response = new Response(work);
            return response.BuildJsonResponse();
        }
        catch (Exception ex)
        {
            _logger.Error(ex, "{Application:l} - {SourceContext:l}: Error 
            calling 'VssAPI'.", applicationName);
            return ex.Message;
        }
    }

使用 GET 通过 postman 进行测试:

http://localhost:57765/API.svc/CreateWorkItem?title=blash&description=bkkdkd&ptid=BDC19072-9016-4CB8-8741-CDFAF52D0E40&assigned=assigned&vstsid=543

最佳答案

REST Web Api 库的最新稳定版本包含一些已知问题和注释:.NET Client Library - WorkItemTrackingHttpClient GetCommentsAsync does not return the list of comments

关于c# - 通过 Visual Studio Team Services 和 Team Foundation Server 的 REST API 概述从 Microsoft vso WorkItem 访问评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47911979/

相关文章:

visual-studio - Visual Studio Team System 有利于 Solo Dev

c# - 如何获取文件添加到 TFS 的日期

c# - XElement.Load 和 XDocument.Load 之间有什么区别?

c# - 我应该如何在 C# > 4.0 中运行后台线程

Asp.NET targetFramework 版本和 IIS 应用程序池版本不匹配

windows - 无法远程运行 powershell 脚本,导致 Azure 中的测试代理部署失败

c# - 如何避免循环并重构 C# 代码

c# - 如何从 Httpclient.SendAsync 调用获取和打印响应

c# - 如何在 asp.net 中显示选项卡控件

asp.net - 什么是动词 ="*"?