gpt4 book ai didi

f# - 如何从 fsharp 使用 libgit2sharp

转载 作者:行者123 更新时间:2023-12-03 21:21:58 25 4
gpt4 key购买 nike

这是在 Server 2016net471这应该表现得像 windows 10 .

所以我通过nuget LibGit2Sharp prerelease下载在我的 paket.dependencies , 解析为

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

我无法引用 dll来自 LibGit2Sharp.NativeBinaries ,因为它抛出
> #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

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

最佳答案

如果您通过 kernel32 的 LoadLibrary 加载 native dll,它应该可以工作。这有帮助吗?
另见 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);

关于f# - 如何从 fsharp 使用 libgit2sharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51022648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com