Going Native
As I typically do, I’m adding this mainly as a reminder to myself; but others might find it useful.
I’m currently in the process of setting up several machines so that I can play with the native ahead-of-time code compiler functionality in .NET 8.
Of course, this includes a couple of Linux machines; in my case I’m planning on the following (to start with):
- Windows 11
- Debian Linux 11 (x86)
- Debian Linux 12 (x64)
- Raspberry Pi OS (Arm64)
Why the need for different machines; well, I’d like to do some testing in the real world and see what the experience is like between these different targets. Additionally, as it turns out, it is not possible to natively cross-compile on Windows to target a different platform; so will need to (at minimum) spin up some sort of virtual environment for this process to take place. GitHub actions can certainly be leveraged here and I’m planning on exploring that more as I progress; but for now I’m trying to wrap my head around what is necessary on these physical machines.
Install .NET 8 (Linux)
Since I’m installing on a Debian distro I’m fortunate enough that Microsoft has a helpful document.
Debian 11
1
2
3
wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
And then…
1
2
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-8.0
Debian 12
1
2
3
wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
And then…
1
2
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-8.0
Raspberry Pi OS
A note on the Install the .NET SDK or the .NET Runtime on Debian document states:
Using a package manager to install .NET from the Microsoft package feed only supports the x64 architecture. Other architectures, such as Arm, aren’t supported by the Microsoft package feed.
This kind of sucks; however, further down on the page are instructions for manual and/or Scripted install. Additionally, I also found Deploy .NET apps on ARM single-board computers; which appears to utilize the scripted install method.
Use wget
to download the script…
1
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
Grant execution permission…
1
chmod +x ./dotnet-install.sh
Install latest .NET version, including SDK.
1
./dotnet-install.sh --version latest
alternatively (as found on the Deploy .NET apps on ARM single-board computers page)…
1
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel STS
Environment
You will most likely want to update the environment variables…
I’m using the Bash Shell, so the settings should be located in either ~/.bash_profile
or ~/.bashrc
…
DOTNET_ROOT
export DOTNET_ROOT=$HOME/.dotnet
PATH
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
The following was found on the Deploy .NET apps on ARM single-board computers page.
1
2
3
echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.bashrc
echo 'export PATH=$PATH:$HOME/.dotnet' >> ~/.bashrc
source ~/.bashrc
Dependencies
These should automatically be installed as part of dotnet; however, may need to done individually if you share (publish) as self-contained application:
libc6
libgcc-s1
libgssapi-krb5-2
libicu63
(for 10.x)libicu67
(for 11.x)libicu72
(for 12.x)libssl1.1
libstdc++6
zlib1g
To install these individually, you can use the apt install
command, for example (for the libc6
package):
1
sudo apt install libc6
Native AOT Deployment
In order to compile natively on Linux, you will also need to have the clang
and zlib1g-dev
packages installed.
1
sudo apt-get install clang zlib1g-dev
And to publish (compile) your application natively:
1
dotnet publish -p:PublishAot=true
For even more details (and suggestions), check out this document.
Targets (RIDs)
It is possible to specify a target platform on the dotnet publish
command-line using the -r:*RID*
parameter:
Windows
- win-x64
- win-x86
- win-arm64
Linux
- linux-x64
- linux-musl-x64
- linux-musl-arm64
- linux-arm
- linux-arm64
- linux-bionic-arm64
macOS
- osx-x64
- osx-arm64
iOS
- ios-arm64
Android
- android-arm64
See here for more details.
Notes
As I stated at the beginning, these are just some notes at this stage and not meant to be any sort of a hands-on step-by-step guide.
I’ll probably return to this document in the future as I continue to learn more and fine tune these details as I progress.