如何在F#中使用libgit2sharp

4

这是在 Server 2016 上,使用 net471,应该和 windows 10 的行为类似。

因此,我正在通过 paket.dependencies 以预发布方式下载 nuget LibGit2Sharp,它将解析为

LibGit2Sharp (0.26.0-preview-0027)
LibGit2Sharp.NativeBinaries (1.0.226) - restriction: >= netstandard2.0

在新的fsi环境下(使用ionide),我可以引用LibGit2Sharp.dll并打开LibGit2Sharp命名空间,但实例化一个Repository会抛出以下错误:
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

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

3
我认为将此作为错误报告发送给libgit2sharp项目可能更好;例如,3天前在https://github.com/libgit2/libgit2sharp/issues/1585上发现了非常类似的症状,尽管是在Ubuntu Linux而不是Windows上。 - rmunn
1
谢谢,我创建了这个问题 https://github.com/libgit2/libgit2sharp/issues/1588。我先在这里问了一下,因为我不确定我使用库的尝试是否正确。在.NET领域中,很难找到适当的说明。很多时候都是假定你已经有相关知识。 - fbehrens
1
Github问题已创建 https://github.com/libgit2/libgit2sharp/issues/1588 - fbehrens
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接