如何从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.
更多推荐
发布评论