【问题标题】:How to provide credentials to Fetch() and Pul() methods?如何为 Fetch() 和 Pul() 方法提供凭据?
【发布时间】:2014-04-29 21:03:44
【问题描述】:

我正在寻找一个很好的干净示例,说明如何使用 lidgit2sharp 进行拉动。我在这里举了一个提取的例子,但是对 Credentials 的引用抛出了一个异常。

using (var repo = new Repository(workingDir, null))
{
    Remote remote = repo.Network.Remotes.Add("master", repoUrl);
    repo.Network.Fetch(remote, 
    {    
        Credentials credentials = new Credentials
        {
            Username = "username",
            Password = "password"
        }
    });
}

例外是无法创建抽象类的实例或 接口'LibGit2Sharp.Credentials'

【问题讨论】:

    标签: libgit2sharp


    【解决方案1】:

    它在错误中告诉你:Credentials 是一个抽象类、接口等等。

    试试这个:

    Credentials credentials = new UsernamePasswordCredentials()
    {
    
            Username = "username",
            Password = "password"
    }
    

    【讨论】:

    • 是的!工作!谢谢....记录在哪里?我到处找。
    • @MightyUgh 据我所知......这不是真的。我是通过 IntelliSense 的力量发现的。
    • 测试中有一点 documentation。这确实可能不够明显。如果您愿意伸出援手,我们很乐意合并一个拉取请求以改善这种状态;-)
    • 此 API 已过时,请使用 CredentialsProvider instead
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 2022-08-04
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多