0

我们正在迁移一些过去在本地 TFS 服务器上运行但现在需要在 Azure DevOps(以前是团队服务)上运行的代码。我使用的凭据已经过验证,可以成功向我们的 DevOps 组织实例进行身份验证,但在引用

Microsoft.TeamFoundationServer.ExtendedClient

NuGet 包总是导致TF30063: You are not authorized to access https://dev.azure.com/<myOrg> 下面发布的代码用于通过非交互式身份验证进行身份验证。我是否需要使用不同的身份验证机制或不同的凭据类型才能使其正常工作?

System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(_userName, DecryptedPassword, _domain);
try
{
    // Create TeamFoundationServer object
    _teamFoundationCollection = new TfsTeamProjectCollection(_serverUrl, networkCredential);
    _teamFoundationCollection.Authenticate();
}
catch (Exception ex)
{
    // Not authorized
        throw new TeamFoundationServerException(ex.Message, ex.InnerException)
}
4

1 回答 1

0

由于您想使用 .Net 客户端库,您可以参考以下链接:

https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-libraries?view=azure-devops

使用模式:

using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;

const String c_collectionUri = "https://dev.azure.com/fabrikam";
const String c_projectName = "MyGreatProject";
const String c_repoName = "MyRepo";

// Interactively ask the user for credentials, caching them so the user isn't constantly prompted
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();

// Connect to Azure DevOps Services
VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);

// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();

// Get data about a specific repository
var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).Result;
于 2019-05-06T06:06:45.607 回答