Tod*_*odd 2 git tfs libgit2sharp azure-devops
我正在尝试使用LibGit2Sharp克隆VSTS(Visual Studio Team Services)存储库。我正在设置CredentialsHandler
并UsernamePasswordCredentials
代表我的Microsoft帐户的凭据,得到的结果是:
LibGit2Sharp.LibGit2SharpException was unhandled
HResult=-2146233088
Message=Too many redirects or authentication replays
Source=LibGit2Sharp
Run Code Online (Sandbox Code Playgroud)
如果我什至无法传递我的真实用户名和密码,我不确定是否可行。
我也尝试过使用这里DefaultCredentials
提到的方法,但这似乎仅用于TFS,而不是VSTS(用于TFS的NTLM凭据)。
首先,您需要为您的帐户启用备用身份验证。请按照以下步骤进行操作:
然后,您可以使用备用凭据对VSTS进行身份验证。以下代码显示了如何向VSTS进行身份验证并执行克隆作业。
using LibGit2Sharp;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string surl = "https://youraccount.visualstudio.com/DefaultCollection/_git/Remoterepo";
string lpath = "C:\\LocalPath";
CloneOptions co = new CloneOptions();
string un = "alternativeusername";
string pwd = "alternativepassword";
Credentials ca = new UsernamePasswordCredentials() {Username = un, Password = pwd };
co.CredentialsProvider = (_url, _user, _cred) => ca ;
Repository.Clone(surl,lpath,co);
}
}
}
Run Code Online (Sandbox Code Playgroud)