TF30063:您无权访问https://dev.azure.com/MyProject

时间:2019-08-05 09:01:13

标签: c# tfs visual-studio-2017 azure-devops

我正在尝试使用VS 2017将项目连接到Azure DevOps。 原因:从本地DevOps迁移到Azure-DevOps。 错误:TF30063:您无权访问https://dev.azure.com/MyProject 登录:两要素认证。 如何在带有VS 2017的Azure DevOps中为我的项目创建测试计划?

我已经在VS 2017中连接了Azure-DevOps,并且可以使用浏览器( Visual Studio,视图->其他Windows-> Web浏览器)查看我的项目。但是使用代码我无法访问

NetworkCredential netCred = new NetworkCredential("username@mail.com", "password");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(_newServer), tfsCred);

 tpc.EnsureAuthenticated();
 tpc.Authenticate();

Log in with two factor authentication

2 个答案:

答案 0 :(得分:1)

请考虑使用Microsoft.TeamFoundationServer.Client nuget软件包。尝试以下步骤:

string PAT = "<your_pat>";
VssConnection connection = new VssConnection(new Uri("<your_url>"), new VssBasicCredential(string.Empty, PAT));
TestPlanClient = Connection.GetClient<TestPlanHttpClient>();
  • 然后您可以创建一个测试计划
TestPlanCreateParams newPlanDef = new TestPlanCreateParams()
{
    Name = TestPlanName,
    StartDate = StartDate,
    EndDate = FinishDate,
    AreaPath = AreaPath,
    Iteration = IterationPath
};

var test_plan =  TestPlanClient.CreateTestPlanAsync(newPlanDef, TeamProjectName).Wait();

答案 1 :(得分:1)

您不能直接使用邮件帐户,而应使用备用凭据(https://dev.azure.com/{org}/_usersSettings/altcreds)。

或者您可以使用个人访问令牌

VssCredentials Credentials = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "your personal acccess token"));
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://dev.azure.com/{org{"), Credentials);

您还可以在运行时指定电子邮件帐户:

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://{org}.visualstudio.com"), new VssClientCredentials());

NuGet软件包:Microsoft.TeamFoundationServer.ExtendedClient