如何从wpf app或其他一些网络应用程序在线创建Visual Studio中的bug工作项目?(How create bug work item in visual studio online fr

编程入门 行业动态 更新时间:2024-10-24 16:24:46
如何从wpf app或其他一些网络应用程序在线创建Visual Studio中的bug工作项目?(How create bug work item in visual studio online from wpf app or some other web app?)

我有一个在WPF应用程序中管理的错误列表。 我想在VSO工作项中创建bug。 是否有可用于在Visual Studio Online中创建bug或任务等工作项的API?

I have a bugs list managed in a WPF app. I would like to create the bug in the VSO work item. Is there an API available to create work items like bug or task in Visual Studio Online?

最满意答案

是的,有REST API来创建工作项 。 示例代码如下:

using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; ... public void CreateBug() { string _personalAccessToken = "your personal access token"; string _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _personalAccessToken))); Object[] patchDocument = new Object[4]; patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Authorization Errors" }; patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http://msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; //use the httpclient using (var client = new HttpClient()) { //set our headers client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); //serialize the fields array into a json string var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, "https://accountname.visualstudio.com/fabrikam/_apis/wit/workitems/$Bug?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; //if the response is successfull, set the result to the workitem object if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; } } }

更多细节,你可以参考创建bug 。

Yes, there has the REST API to create a work item. The example code as:

using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; ... public void CreateBug() { string _personalAccessToken = "your personal access token"; string _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _personalAccessToken))); Object[] patchDocument = new Object[4]; patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Authorization Errors" }; patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http://msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; //use the httpclient using (var client = new HttpClient()) { //set our headers client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); //serialize the fields array into a json string var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, "https://accountname.visualstudio.com/fabrikam/_apis/wit/workitems/$Bug?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; //if the response is successfull, set the result to the workitem object if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; } } }

More details, you can refer create bug.

更多推荐

本文发布于:2023-07-31 19:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347346.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   或其他   应用程序   项目   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!