我正在尝试使用控制台应用程序的客户端API连接到visualstudio.com上托管的TeamFoundationServer,但出现此错误:
TF400813: Resource not available for anonymous access. Client
我的代码:

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

    TfsTeamProjectCollection collection =
        new TfsTeamProjectCollection(
            collectionUri,
            new System.Net.NetworkCredential(@"[email protected]", "MyPassword"));

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

最佳答案

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

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/

10-13 06:38