首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用libgit2sharp与LINQPad?

使用libgit2sharp与LINQPad?
EN

Stack Overflow用户
提问于 2013-06-07 11:32:03
回答 6查看 897关注 0票数 6

我有带有LINQPad的NuGet版本,并添加了libgit2sharp,但这依赖于另一个(本机) dll。

我试过:

  • 复制他们我的系统目录。
  • 将它们放在我添加到路径中的一个单独的目录中。
  • 将它们放在LINQPads插件目录中。
  • 在我将查询运行到Assembly.GetExecutingAssembly().Location时复制它们

我只是尝试用这个库读取日志,并将它作为LINQPad中的一个片段来阅读,虽然我认为如果其他程序都失败了,我可以将它变成一个控制台应用程序。

有人使用libgit2sharp和LINQPad,并能解释如何让他们在一起玩得很好?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2013-06-07 12:58:40

将dll放入路径中的文件夹或将dll的位置添加到路径中应该可以工作(并且适合我)

也许你的改变还没有生效。尝试关闭并重新打开LinqPad,如果失败,请退出并返回窗口。

票数 7
EN

Stack Overflow用户

发布于 2016-10-09 07:11:46

编辑:LINQPad再次支持开箱即用( LINQPad 5.10.02 -在写文章时的测试版)。现在不需要任何解决办法。

不幸的是,这在LibGit2Sharp v0.22中又被破坏了。此包不再包含LibGit2Sharp.dll位于/libs中的子文件夹中的本机二进制文件。相反,它们位于一个独立的依赖NuGet包中,该包依赖于修补项目文件。由于LINQPad不使用项目文件,这将失败。

您可以按照其他答案中的建议添加一个初始化方法来填充本机文件夹位置的路径变量,从而解决这一问题。以下代码将在任何具有当前LibGit2Sharp的机器上不受修改地工作:

代码语言:javascript
复制
void Main()
{
   ... your query here...
}

static UserQuery()
{
   const string pathEnvVariable = "PATH";
   char slash = Path.DirectorySeparatorChar;
   char pathSep = Path.PathSeparator;

   // The correct native binary file is located under a folder ending in
   // "windows\x86" or "windows\amd64" or "win7-x86\native" or "win7-x64\native".
   // This may change in later LibGit2Sharp releases.
   string nativeStem1 = $"{slash}windows{slash}{(IntPtr.Size == 8 ? "amd64" : "x86")}";
   string nativeStem2 = $"{(IntPtr.Size == 8 ? "-x64" : "-x86")}{slash}native";

   // Locate the root folder in the NuGet package. This contains folders for the
   // main package (LibGit2Sharp) plus dependencies (LibGit2Sharp.NativeBinaries).
   var nugetRoot = new FileInfo (typeof (Repository).Assembly.Location)
      .Directory.Parent.Parent.Parent;

   var nativeBinaryPath = nugetRoot
      .GetFiles ("*.dll", SearchOption.AllDirectories)
      .Single (d => d.DirectoryName.EndsWith (nativeStem1, StringComparison.OrdinalIgnoreCase) ||
                    d.DirectoryName.EndsWith (nativeStem2, StringComparison.OrdinalIgnoreCase))
      .Directory
      .FullName;

   string currentPaths = Environment.GetEnvironmentVariable (pathEnvVariable);

   if (!(pathSep + currentPaths + pathSep).ToUpperInvariant().Contains
      (pathSep + nativeBinaryPath.ToUpperInvariant() + pathSep))
   {
      Environment.SetEnvironmentVariable (pathEnvVariable, currentPaths + pathSep + nativeBinaryPath);
   }
}

注意,您不需要显式调用此方法,因为它位于静态构造函数中。

另一个解决方法是在NuGet上发布另一个NuGet包,其中包括LibGit2Sharp.dll所在的预期位置下的本机二进制文件(NativeBinarisx86\git2-785d8c4.dll和NativeBinaries\ and 86\git2-785d8c4.dll)-例如下载LibGit2Sharp 0.21.0.176。

票数 5
EN

Stack Overflow用户

发布于 2013-09-18 09:01:19

最后,我在运行时添加了相关路径,使用:

代码语言:javascript
复制
void SetUpNativeBinaries(){
    var appDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
    var packageVersion = "LibGit2Sharp.0.14.0.0";// may read from PackageInfo
    var processorArchitecture = IntPtr.Size==8?"amd64":"x86";
    var libgitNativeBinaryPath = Path.Combine(appDataLocal, "LINQPad", "NuGet", "LibGit2Sharp", packageVersion, "NativeBinaries", processorArchitecture);
    libgitNativeBinaryPath.Dump();

    var pathEnvVariable = "PATH";
    var currentPaths = Environment.GetEnvironmentVariable(pathEnvVariable);
    var combinedPaths = String.Format(
        System.Globalization.CultureInfo.InvariantCulture,
        "{0}{1}{2}",
        libgitNativeBinaryPath,
        Path.PathSeparator,
        currentPaths);

    Environment.SetEnvironmentVariable(pathEnvVariable, combinedPaths);
}

将其保存为"C#程序“,您可以立即开始:

代码语言:javascript
复制
void Main()
{
    SetUpNativeBinaries();
    var repoWorkingDir = @"C:\temp\libgit2_repo";
    var repo = new Repository(repoWorkingDir);

    repo.Config.Dump();
    repo.Branches.Dump();
    repo.Index.RetrieveStatus().Dump();
    //...
}

更新 这是一个封闭的问题,修补程序是从0.14.1.0版开始提供的。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16983085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档