I want to build an ASP.NET Core Web API service to run on an arm (cortex-A7) device with an angstrom based linux.
Question: What is the best route to follow?
My main concern is the angstrom distribution, which is not supported by dotnet core out of the box. Any advice is welcome!
Edit, Open Questions:
You can use the portable linux-arm
runtime build of .NET Core.
On your build machine, make sure that dotnet --version
returns a 2.0
, preview, or higher version (at the time of writing: 2.0.0-preview1-005977
).
dotnet new mvc
dotnet restore -r linux-arm
dotnet publish -r linux-arm /p:MvcRazorCompileOnPublish=false
bin/Debug/netcoreapp2.0/linux-arm/publish
to your target machine and run with ./nameOfTheProject
Since you probably want to develop locally as well, you'd want to edit the project (.csproj
) file like this (<PropertyGroup>
):
<RuntimeIdentifiers>linux-arm</RuntimeIdentifiers>
<MvcRazorCompileOnPublish Condition=" '$(RuntimeIdentifier)' != 'linux-arm' ">true</MvcRazorCompileOnPublish>
This way you can use both dotnet restore
, dotnet run
and dotnet publish
during development or other deploys without additional parameters and when ready to deploy to arm, only use:
dotnet publish -c Release -r linux-arm
and use the resulting binaries from bin/Release/netcoreapp2.0/linux-arm/publish
(or pass an additional -o ../publish-output
argument)
Based on Martin Ulrichs suggestions I had partial success in cross-compiling a self-contained executable for arm. The code is cross-compiled on a Ubuntu.16.04-x64
machine and runs on a raspberry pi 2 (GNU/Linux 4.1.17-v7+ armv7l
) without installing the dotnet runtime on the PI.
On the build machine, Ubuntu.16.04-x64 with dotnet --version = 2.0.0-preview1-005977
, run the following:
mkdir foobar; cd foobar
dotnet new console
dotnet restore -r linux-arm
dotnet publish -r linux-arm
This produces a 31MB publish folder with 174 files. Copy those over to the arm device. Note that the resulting executable will not run on the build machine (wrong architecture).
On the arm device
First, you have to install some required libraries for the dotnet runtime. Unfortunatley this is debian, and probably not suitable for angstrom (this is why I don't mark this as answer). I picked only non-dev prerequisites from here, since the app is not compiled on the PI.
sudo apt-get install libunwind8 libicu52 gettext liblttng-ust-ctl2 liblttng-ust0
This list may contain too much / not enough depending on the actual application. Finally, run the self-contained application
chmod +x bin/Debug/netcoreapp2.0/linux-arm/publish/foobar
bin/Debug/netcoreapp2.0/linux-arm/publish/foobar
The execution speed (slow as hell for writing "Hello World!" to the console) indicates that this is actually byte code bootstrapped by some kind of included dotnet clr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With