【问题标题】:How to use libgit2sharp with Xamarin.Mac?如何在 Xamarin.Mac 中使用 libgit2sharp?
【发布时间】:2017-04-13 22:10:57
【问题描述】:

我正在尝试在 Mac 上使用出色的库 libgit2sharp。因此,我使用 Xamarin Studio 创建了一个 Mac 应用程序来从 Git 存储库中读取信息。

当我在普通的单声道可执行文件(目标 Mono / .NET4.5)中使用该库时,一切正常。 但是当我创建一个 Xamarin.Mac 项目时,会出现以下错误,并且我看不到解决方法:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: git2-a5cf255
  at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_init ()
  at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00006] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00058] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
   --- End of inner exception stack trace ---
  at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
  at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x0007e] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: git2-a5cf255
  at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_init ()
  at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00006] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00058] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
   --- End of inner exception stack trace ---
  at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 
  at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x0007e] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0 

在谷歌搜索时,我发现很多主题都以 “在您的机器上构建 libgit2sharp 以获取正确的 .dylib 文件”结束。这在过去可能是一个问题,但现在不是了,所以这对我没有帮助。如前所述,我可以轻松地将 libgit2sharp 与单声道可执行文件一起使用。

顺便说一句,我不能使用 Nuget 包“libgit2sharp”,因为它说 Xamarin.Mac 目标不兼容。我正在使用包“libgit2sharp.portable”,它在安装或编译时不会引发错误。这只是运行时上面的错误消息。

我的示例应用程序可在此处下载:https://files.fm/u/7eq55jjq

有什么建议可以解决这个问题吗?谢谢!

更新 该错误可能暗示 dylib 的路径错误(“找不到 DLL”),但事实并非如此。该文件正是它应该在的位置。

【问题讨论】:

    标签: c# git macos xamarin.mac libgit2sharp


    【解决方案1】:

    天哪,我离得太近了。 Philippe 也在那里:确保将 dylib 文件放置到输出目录中的文件夹中是不正确的(就像 Nuget 包自动执行的那样),即 /lib/osx/libgit2-1196807.dylib

    相反,我发现 dylib 文件必须放在 *.app 文件中。 但 Xamarin Studio 没有手动执行此操作,而是为 Xamarin 提供了一个名为“Native References”的东西.Mac 项目。

    我应该以前看过这个“本地参考”。对不起,伙计们,但也许这对某人有帮助。

    【讨论】:

      【解决方案2】:

      我很确定问题出在单独的 nuget 包“Libgit2sharp.NativeBinaries”中的本机库未复制到输出文件夹中(应该在子目录“lib”中)。

      复制通常由目标在项目构建期间完成。

      【讨论】:

      • 看起来是这样,是的。但是文件就在那里,它们就是路径指向的地方。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多