<myOrg> 无法访问使用 TFS 扩展客户端版本 15 https://dev.azure.com/



我们正在迁移一些用于与前提TFS服务器相对的代码,但现在需要与Azure DevOps(以前的团队服务(竞争。我使用的凭据已经过验证以成功地验证我们的DevOps组织实例,但是在引用

后运行以下代码

microsoft.team -foundationserver.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)
}

由于要使用.NET客户端库,因此您可以参考以下链接:

https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-lient-lient-lient-limbaries?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;

最新更新