在 Windows 上的 Xamarin studio 中构建时,Libgit2sharp 找不到 git2-*.dll
Libgit2sharp can't find git2-*.dll when built in Xamarin studio on Windows
我正在尝试使用 Xamarin Studio 在 Windows 上构建 C# 桌面应用程序。导入 LibGit2Sharp 包(以及 LibGit2Sharp.NativeBinaries 包)后,任何实际使用该库的尝试都会导致以下情况之一:
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: git2-785d8c4
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_config_find_xdg (LibGit2Sharp.Core.Handles.GitBuf)
at LibGit2Sharp.Core.Proxy.ConvertPath (System.Func`2 pathRetriever) [0x00006] in <filename unknown>:0
at LibGit2Sharp.Core.Proxy.git_config_find_xdg () [0x00000] in <filename unknown>:0
at LibGit2Sharp.Configuration..ctor (LibGit2Sharp.Repository repository, System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation, System.String xdgConfigurationFileLocation, System.String systemConfigurationFileLocation) [0x00032] in <filename unknown>:0
at LibGit2Sharp.Configuration.BuildFrom (System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation, System.String xdgConfigurationFileLocation, System.String systemConfigurationFileLocation) [0x00000] in <filename unknown>:0
at LibGit2Sharp.Configuration.BuildFrom (System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation) [0x00000] in <filename unknown>:0
at bravura.tools.git.helper.operations.CoreSettings.run () [0x00015] in C:\code\bravura\git-helper\operations\CoreSettings.cs:37
at bravura.tools.git.helper.operations.CoreMenu.OnButtonOkReleased (System.Object sender, System.EventArgs e) [0x00020] in C:\code\bravura\git-helper\operations\CoreMenu.cs:43
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.Reflection\MonoMethod.cs:295
我发现手动将 dll 和 pdb 放在根输出目录中可以解决问题,但这并不能带来良好的构建过程。确实,应该有一种方法可以将 "NativeBinaries*" 目录添加到加载路径。我已经尝试手动加载库,但由于它不是 .NET,所以该选项不起作用。
我是不是遗漏了什么明显的东西?这是一个常见的问题吗?我只是在胡思乱想?
我已经检查了以下问题无济于事:
- LibGit2Sharp fails to find git2.dll
- DllNotFoundException and PATH environment variable
环顾四周后,Matt Ward, I found a working answer while reading Loading dlls from path specified in SetdllDirectory in c#, or more specifically, this comment 指出了正确的方向。
string newPath = Environment.GetEnvironmentVariable("PATH") +
";" + Environment.CurrentDirectory + "\NativeBinaries\x86\";
Environment.SetEnvironmentVariable("PATH", newPath);
我正在尝试使用 Xamarin Studio 在 Windows 上构建 C# 桌面应用程序。导入 LibGit2Sharp 包(以及 LibGit2Sharp.NativeBinaries 包)后,任何实际使用该库的尝试都会导致以下情况之一:
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: git2-785d8c4
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_config_find_xdg (LibGit2Sharp.Core.Handles.GitBuf)
at LibGit2Sharp.Core.Proxy.ConvertPath (System.Func`2 pathRetriever) [0x00006] in <filename unknown>:0
at LibGit2Sharp.Core.Proxy.git_config_find_xdg () [0x00000] in <filename unknown>:0
at LibGit2Sharp.Configuration..ctor (LibGit2Sharp.Repository repository, System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation, System.String xdgConfigurationFileLocation, System.String systemConfigurationFileLocation) [0x00032] in <filename unknown>:0
at LibGit2Sharp.Configuration.BuildFrom (System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation, System.String xdgConfigurationFileLocation, System.String systemConfigurationFileLocation) [0x00000] in <filename unknown>:0
at LibGit2Sharp.Configuration.BuildFrom (System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation) [0x00000] in <filename unknown>:0
at bravura.tools.git.helper.operations.CoreSettings.run () [0x00015] in C:\code\bravura\git-helper\operations\CoreSettings.cs:37
at bravura.tools.git.helper.operations.CoreMenu.OnButtonOkReleased (System.Object sender, System.EventArgs e) [0x00020] in C:\code\bravura\git-helper\operations\CoreMenu.cs:43
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.Reflection\MonoMethod.cs:295
我发现手动将 dll 和 pdb 放在根输出目录中可以解决问题,但这并不能带来良好的构建过程。确实,应该有一种方法可以将 "NativeBinaries*" 目录添加到加载路径。我已经尝试手动加载库,但由于它不是 .NET,所以该选项不起作用。
我是不是遗漏了什么明显的东西?这是一个常见的问题吗?我只是在胡思乱想?
我已经检查了以下问题无济于事:
- LibGit2Sharp fails to find git2.dll
- DllNotFoundException and PATH environment variable
环顾四周后,Matt Ward, I found a working answer while reading Loading dlls from path specified in SetdllDirectory in c#, or more specifically, this comment 指出了正确的方向。
string newPath = Environment.GetEnvironmentVariable("PATH") +
";" + Environment.CurrentDirectory + "\NativeBinaries\x86\";
Environment.SetEnvironmentVariable("PATH", newPath);