可以将依赖于 System.Net.Http.WinHttpHandler 的库部署到 Linux

Can a library that depends on System.Net.Http.WinHttpHandler be deployed to Linux

我正在考虑使用 Consul library for .NET which supports NETSTANDARD1.3. As I was adding the package I saw it depends on System.Net.Http.WinHttpHandler,它又添加了 win32 原语包。

我找不到任何文档说明这些包如何在 Linux 上工作。我假设它们不会工作,但它们可能会提供垫片层。

有人对这些包有任何经验吗?

编辑:

作为独立部署部署到 Ubuntu 会产生以下结果。

Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Net.Http.Native': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Interop.HttpInitializer.EnsureCurlIsInitialized() at Interop.HttpInitializer..cctor() --- End of inner exception stack trace --- at Interop.HttpInitializer.Initialize() at Interop.Http..cctor() --- End of inner exception stack trace --- at Interop.Http.GetSupportedFeatures() at System.Net.Http.CurlHandler..cctor() --- End of inner exception stack trace --- at System.Net.Http.CurlHandler..ctor() at Consul.ConsulClient.ConsulClientConfigurationContainer..ctor() at Consul.ConsulClient..ctor(Action`1 configOverride, Action`1 clientOverride, Action`1 handlerOverride) at REstateScratchPad.Program.Main(String[] args) Aborted (core dumped)

Linux 实际上支持这种依赖性,因为它是 .NETStandard 的一部分,并且为 CURL 处理程序准备了填充码。

部署应用程序确实导致了原始 post 中出现的错误,但安装 SDK 解决了这些问题。

旁注:我认为我不需要 SDK 来 运行 自包含部署。

我认为您不需要安装 SDK,因为我能够让它正常工作。您使用的 Ubuntu 是哪个版本?您是否遵循了 https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/ 中详述的步骤(下面也有详细说明)?

我这么说是因为我构建了一个测试应用程序,它在根本没有安装 SDK 的情况下也能正常工作:

  1. 根据上述指南编辑您的 project.json 并删除 "platform": true。添加一个 runtimes: {} 元素,对我来说是: "runtimes": { "win81-x64": {}, "ubuntu.14.04-x64": {} }

  2. 在我这样做之后,我能够执行 dotnet restoredotnet build -r ubuntu.14.04-x64 这有效,但只在目录中删除了 3 个文件并且不能 运行 没有 SDK。

  3. 我做了 dotnet publish -c release -r ubuntu.14.04-x64 并启动了一个 Vagrant box 运行ning Ubuntu 14.04,apt-get install libunwind8,然后 运行 我的程序:/vagrant/bin/release/netcoreapp1.0/ubuntu.14.04-x64/publish/ConsoleApp1.该程序所做的只是位于 Consul.NET project 的 README.md 中的示例函数,并且在我在 VM 中启动 Consul 副本后它能够正确打印 "Hello Consul"。