F# 如何从fsharp使用libgit2sharp

F# 如何从fsharp使用libgit2sharp,f#,libgit2,libgit2sharp,F#,Libgit2,Libgit2sharp,这是在带有net471的server2016上,其行为应类似于windows10 因此,我通过我的paket.dependencies中的nuget-LibGit2Sharp预发行版下载,它解析为 LibGit2Sharp (0.26.0-preview-0027) LibGit2Sharp.NativeBinaries (1.0.226) - restriction: >= netstandard2.0 在新的fsi(使用ionide)中,我可以引用LibGit2Sharp.dll并打

这是在带有
net471
server2016
上,其行为应类似于
windows10

因此,我通过我的
paket.dependencies
中的
nuget-LibGit2Sharp预发行版
下载,它解析为

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

我错过了什么?如何使用已编译的库?

如果通过内核32的LoadLibrary加载本机dll,它应该可以工作。这有用吗

另见

[]
extern IntPtr LoadLibrary(字符串lpFileName);

我怀疑这可能会更好地作为libgit2sharp项目的bug报告;例如,从3天前开始,虽然在Ubuntu Linux而不是Windows上出现了非常类似的症状。谢谢,我创建了这个问题。我先问这里,因为我不确定我使用图书馆的尝试是否正确。我发现在.NET领域很难找到合适的指令。通常情况下,知识是假定的。Github问题就是由此产生的
> #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
[<DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
extern IntPtr LoadLibrary(string lpFileName);