这是在带有net471的Server 2016上,它的行为应该类似于windows 10。
所以我在我的paket.dependencies中通过nuget LibGit2Sharp prerelease下载,它解析为
LibGit2Sharp (0.26.0-preview-0027)
LibGit2Sharp.NativeBinaries (1.0.226) - restriction: >= netstandard2.0在新的fsi (使用ionide )中,我可以引用LibGit2Sharp.dll并打开LibGit2Sharp名称空间,但实例化存储库会抛出以下错误:
Microsoft (R) F# Interactive version 10.1.0 for F# 4.1
> #r "../../packages/play/LibGit2Sharp/lib/netstandard2.0/LibGit2Sharp.dll";;
--> Referenced 'd:\scripts2dev\libwba\src\play\../../packages/play/LibGit2Sharp/lib/netstandard2.0/LibGit2Sharp.dll' (file may be locked by F# Interactive process)
> open LibGit2Sharp;;
> let repo = new Repository("path\to\repo.git");;
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-b0d9952': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary()
at LibGit2Sharp.Core.NativeMethods..cctor()
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.NativeMethods.git_repository_open(git_repository*& repository, FilePath path)
at LibGit2Sharp.Core.Proxy.git_repository_open(String path)
at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter)
at <StartupCode$FSI_0003>.$FSI_0003.main@() in d:\scripts2dev\libwba\src\play\LibGit2Sharp.fsx:line 4
Stopped due to error而且我不能引用来自LibGit2Sharp.NativeBinaries的dll,因为它抛出
> #r @"../..\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll";;
LibGit2Sharp.fsx(7,1): error FS0229: Error opening binary file 'd:\scripts2dev\libwba\src\play\../..\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll': d:\scripts2dev\libwba\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll: bad cli header, rva 0
LibGit2Sharp.fsx(7,1): error FS3160: Problem reading assembly 'd:\scripts2dev\libwba\src\play\../..\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll': Processing of a script fragment has stopped because an exception has been raised我遗漏了什么?如何使用已编译的库?
发布于 2021-06-09 00:17:10
如果你通过kernel32的LoadLibrary加载原生动态链接库,它应该可以工作。这有帮助吗?
另请参阅https://christoph.ruegg.name/blog/loading-native-dlls-in-fsharp-interactive.html
[<DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
extern IntPtr LoadLibrary(string lpFileName);https://stackoverflow.com/questions/51022648
复制相似问题