我们正在迁移一些以前在本地TFS服务器上运行但现在需要在Azure DevOps(以前称为Team Services)上运行的代码。我使用的凭据已经过验证,可以成功验证我们的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)
}
答案 0 :(得分:0)
由于您要使用.Net客户端库,因此可以参考以下链接:
使用模式:
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;