How to provide credentials to Fetch() and Pul() methods?

大憨熊 提交于 2019-12-12 10:04:14

问题


I'm looking for a nice clean example of how to do a pull using lidgit2sharp. I took the example here which does a fetch, but the reference to Credentials is throwing an exception.

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"
        }
    });
}

The exception is Cannot create an instance of the abstract class or interface 'LibGit2Sharp.Credentials'


回答1:


It's telling you in the error: Credentials is an abstract class, interface, whatever.

Try this:

Credentials credentials = new UsernamePasswordCredentials()
{

        Username = "username",
        Password = "password"
}


来源:https://stackoverflow.com/questions/23375239/how-to-provide-credentials-to-fetch-and-pul-methods

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!