gpt4 book ai didi

tfs - 如何以编程方式登录到 VSTS

转载 作者:行者123 更新时间:2023-12-02 02:55:00 24 4
gpt4 key购买 nike

我有一个执行各种操作的自动分支实用程序。我们已升级到 VSTS,但我在使用新服务器的 Tfs 调用时遇到问题:

//login

NetworkCredential netCred = new NetworkCredential("emailAddress", password");

BasicAuthCredential basicCred = new BasicAuthCredential(netCred);

TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);

tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tfsServer = new TfsTeamProjectCollection(new Uri("https://myco.visualstudio.com/mycoll"), tfsCred);

// get a local workspace

VersionControlServer sc = server.GetService(typeof(VersionControlServer)) as VersionControlServer;

... other code

然后砰!“您无权访问 https://myco.visualstudio.com/mycoll

有什么设置吗?

我应该尝试使用 REST API 吗?

我调用的是我不应该调用的东西吗?

我已经尝试了各种 URI 格式,包括 :8080 和路径中的/tfs 都无济于事!

最佳答案

您可以使用 PAT(个人访问 token )访问 VSTS。在 VSTS 中单击您的个人资料,然后转到安全菜单项。您可以在其中定义 PAT。保存 PAT,因为它只会显示一次。

enter image description here

根据您的需要定义范围 enter image description here

您可以使用 PAT 访问 TFS REST API,如以下 PowerShell 示例所示。使用https://yourAccount.visualstudio.comhttps://yourAccount.visualstudio.com/DefaultCollection对于 ColletionUri 参数是可以的。

param(
[Parameter(Mandatory=$true)]
[string] $token,
[Parameter(Mandatory=$true)]
[string] $collectionUri
)



$User=""

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,$token)));
$header = @{Authorization=("Basic {0}" -f $base64AuthInfo)};

$Uri = $collectionUri + '/_apis/projects?api-version=1.0'

$projects = Invoke-RestMethod -Method Get -ContentType application/json -Uri $Uri -Headers $header

您可以在此处找到 C# 代码示例 https://www.domstamand.com/accessing-tfs-2017-programmatically/

关于tfs - 如何以编程方式登录到 VSTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49900012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com