所以这里是我将从 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/