gpt4 book ai didi

c# - 如何从控制台应用程序使用客户端 api 连接到 TeamFoundationServer (tfs)?

转载 作者:可可西里 更新时间:2023-11-01 08:40:39 24 4
gpt4 key购买 nike

我正在尝试连接到托管在 visualstudio.com 的 TeamFoundationServer,使用其客户端 API 和控制台应用程序,但我收到此错误:

TF400813:资源不可用于匿名访问。客户端

我的代码:

private static void Main(string[] args)
{
Uri collectionUri = new Uri("https://MyName.visualstudio.com/DefaultCollection");

TfsTeamProjectCollection collection =
new TfsTeamProjectCollection(
collectionUri,
new System.Net.NetworkCredential(@"MeMail@gmail.com", "MyPassword"));

WorkItemStore workItemStore = collection.GetService<WorkItemStore>();
}

最佳答案

您必须从 TfsTeamProjectCollection 调用 EnsureAuthenticated() 方法:

private static void Main(string[] args)
{
Uri collectionUri = new Uri("https://MyName.visualstudio.com/DefaultCollection");

NetworkCredential credential = new NetworkCredential("USERNAME", "PASSWORD");
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, credential);
teamProjectCollection.EnsureAuthenticated();

WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();

WorkItemCollection workItemCollection = workItemStore.Query("QUERY HERE");

foreach (var item in workItemCollection)
{
//Do something here.
}
}

希望已经解决了您的问题。

关于c# - 如何从控制台应用程序使用客户端 api 连接到 TeamFoundationServer (tfs)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com