我使用以下代码与visual studio在线项目交谈以获取工作项列表。但得到TF30063 unauthorized access error
。
我尝试使用网络信用卡,Windows默认信用卡,VssBasicCredential
和VssCredentials
来访问项目。我尝试清除缓存,通用信用卡。但没有任何工作。我可以从浏览器访问VSO项目,但不能通过此代码访问。
如果我遗失任何内容,请告诉我。
感谢您的帮助。感谢
this.uri = projectUri;
string userName = ConfigurationManager.AppSettings["Username"];
string password = ConfigurationManager.AppSettings["Password"];
NetworkCredential netCred = new NetworkCredential(userName, password);
// VssBasicCredential bsCred = new VssBasicCredential(netCred);
//VssCredentials vssCred = new VssCredentials(bsCred);
// VssCredentials vssCred = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(netCred));
tpc = new TfsTeamProjectCollection(new Uri(uri), netCred);
workItemStore = WorkItemStore)tpc.GetService(typeof(WorkItemStore));
答案 0 :(得分:1)
只需尝试enable alternate credentials为您的帐户。然后再试一次。
您还可以参考此文章:How to connect to TF Service without a prompt for LiveID credentials
以下示例供您参考以获取工作项列表,它适用于我:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
namespace GetWorkItemList
{
class Program
{
static void Main(string[] args)
{
string info = String.Empty;
NetworkCredential netCred = new NetworkCredential("xxx@outlook.com", "password");
var tpc = new TfsTeamProjectCollection(new Uri("https://xxxx.visualstudio.com"), netCred);
WorkItemStore workItemStore = new WorkItemStore(tpc);
Query query = new Query(workItemStore, "SELECT * FROM WorkItems WHERE [System.TeamProject] = @project", new Dictionary<string, string>() { { "project", "ProjectNameHere" } });
WorkItemCollection wic = query.RunQuery();
foreach (WorkItem item in wic)
{
info += String.Format("WIT:{0} ID: {1} Title: {2}\n", item.Type.Name, item.Id, item.Title);
}
Console.WriteLine(info);
Console.ReadLine();
}
}
}
此外,您还可以尝试使用PAT,点击以下链接查看示例:
答案 1 :(得分:0)
当您计算机上的默认凭据与当前解决方案关联的凭据不匹配时,可能会发生这种情况。您可以通过在Visual Studio中手动登录来解决此问题。打开WebBrowser视图(Ctrl + W,W),然后导航到要使用的帐户的dev.azure.com页面。通过浏览器视图正常登录。然后,团队资源管理器将获取正确的凭据。