如何运行 ASP.NET Core on arm-based custom linux?

How to run ASP.NET Core on arm-based custom linux?

我想在基于 linux 的 arm (cortex-A7) device with an angstrom 上为 运行 构建 ASP.NET 核心 Web API 服务。

问题:最好的路线是什么?

  1. 为 arm7 设备编译 CoreClr、CoreFx 等(可能是 possible,但我不确定埃 linux)。如果可行,发布的字节码应该 运行 在该设备上。
  2. 使用 dotnet native 和 target arm 交叉编译我的 aspnet 应用程序。我找不到有用的信息,但它是可能的。
  3. 还有别的吗?喜欢从我的项目生成 C++ 代码吗?
  4. 为设备编译一个不同的 linux 发行版(可能不行,因为我们需要 Linux Cortex-A7 CPU 和 FreeRTOS Cotex-M4 CPU).

我主要关心的是 angstrom 发行版,开箱即用的 dotnet 核心不支持它。欢迎任何建议!


编辑,未决问题:

您可以使用 .NET Core 的可移植 linux-arm 运行time build。 在您的构建机器上,确保 dotnet --version returns 是 2.0、预览版或更高版本(在撰写本文时:2.0.0-preview1-005977)。

  1. dotnet new mvc
  2. dotnet restore -r linux-arm
  3. dotnet publish -r linux-arm /p:MvcRazorCompileOnPublish=false
  4. bin/Debug/netcoreapp2.0/linux-arm/publish 的内容复制到您的目标机器,并使用 ./nameOfTheProject
  5. 运行

由于您可能也想在本地开发,因此您需要像这样编辑项目 (.csproj) 文件 (<PropertyGroup>):

<RuntimeIdentifiers>linux-arm</RuntimeIdentifiers>
<MvcRazorCompileOnPublish Condition=" '$(RuntimeIdentifier)' != 'linux-arm' ">true</MvcRazorCompileOnPublish>

通过这种方式,您可以在开发或其他部署期间同时使用 dotnet restoredotnet rundotnet publish,无需额外参数,当准备部署到 arm 时,仅使用:

dotnet publish -c Release -r linux-arm

并使用 bin/Release/netcoreapp2.0/linux-arm/publish 生成的二进制文件(或传递额外的 -o ../publish-output 参数)

根据 Martin Ulrichs 的建议,我在为 arm 交叉编译独立的可执行文件方面取得了部分成功。代码在 Ubuntu.16.04-x64 机器上交叉编译,运行s 在 raspberry pi 2 (GNU/Linux 4.1.17-v7+ armv7l) 上交叉编译,没有在 PI 上安装 dotnet 运行time。

在构建机器上、Ubuntu.16.04-x64 和 dotnet --version = 2.0.0-preview1-005977、运行 以下内容:

mkdir foobar; cd foobar
dotnet new console
dotnet restore -r linux-arm
dotnet publish -r linux-arm

这将生成一个包含 174 个文件的 31MB 发布文件夹。将这些复制到手臂设备。请注意,生成的可执行文件不会 运行 在构建机器上(错误的体系结构)。

在手臂装置上

首先,您必须为 dotnet 运行安装一些必需的库。 不幸的是,这是 debian,可能不适合 angstrom(这就是为什么我不将其标记为答案)。 我只选择了非开发人员 prerequisites from here,因为该应用程序未在 PI 上编译。

sudo apt-get install libunwind8 libicu52 gettext liblttng-ust-ctl2 liblttng-ust0

此列表可能包含过多/不足,具体取决于实际应用。最后,运行 独立的应用程序

chmod +x bin/Debug/netcoreapp2.0/linux-arm/publish/foobar
bin/Debug/netcoreapp2.0/linux-arm/publish/foobar

执行速度(将 "Hello World!" 写入控制台非常慢)表明这实际上是由某种包含的 dotnet clr 引导的字节代码。

首先,忘掉埃。您不会从该发行版或其包管理器中获得任何本机依赖项。您也找不到任何有用的埃资源。

改为使用 yocto to build your own OpenEmbedded Core linux distro and add native dependencies during the build. At the time of writing, this can be managed with the meta-aspnet layer from Tragetaschenreadme.md 声明单声道是一项要求,但事实并非如此(现在?)。

一旦原生依赖项(libunwind、libicu 等)在 arm 系统上可用,您可以从 https://github.com/dotnet/core-setup 下载最新的 Linux (armhf) (for glibc based OS) 构建,将其解压到 /opt/dotnet/,并通过 ln -s /opt/dotnet/dotnet /usr/bin/ 创建符号链接。这是 OP 的第 1 号解决方案,通用字节码项目(仅 dotnet publish)可以正常工作。

如果你不喜欢在目标机器上安装 dotnet,你可以编译 -r linux-arm(Martin Ulrich 的建议),这会产生一个巨大的 publish 文件夹,包括 coreclr 和 corefx。然而,在目标机器上安装 dotnet 是所有问题中最小的,将你的应用程序与 dotnet 分开 coreclr/fx/host 更干净(恕我直言)。

关键问题是

  1. 需要哪些依赖项?目前还没有明确的答案。
  2. 如何为您的机器编译它们?

meta-aspnet 层似乎解决了这两个问题(在撰写本文时)。您必须深入研究它以获取更多详细信息,或者按原样使用它。