.NET 5 and Self-Contained Single File Apps on Linux

.NET 5 is out on schedule (but with a reduced scope). The Core branding has gone but it’s the same modern cross-platform codebase and not the old Windows-only Framework.

I’m normally a LTS person (I only upgraded from Ubuntu 18.04 LTS to 20.04 LTS recently, now that 20.10 is out). As you become an experienced engineer you learn to value LTS and stop chasing the latest JavaScript framework of the week. Most of my projects (for example, Huxley 2) will stay on 3.1 LTS until at least next year when .NET 6 LTS comes out.

However, there is one feature of .NET 5 that is quite interesting and I wanted to try out. This feature is self-contained single file apps and it is only available on Linux (not on mac or Windows, yet). This is another area where Linux is a step ahead.

OctoPlot

I’ve upgraded my OctoPlot tool to .NET 5 and produced some self-contained single file app Linux binaries. You can stay on 3.1 and use the 5.0 SDK but the binaries are bigger. I also trimmed out any unused code from the assemblies (including R2R, which is not the same AOT compilation as CoreRT or .NET Native) to get them as small as possible.

The result is a binary under 5MB compressed. This is by no means tiny compared to a Python script but it includes the runtime, making it easy to deploy. This is about a quarter of the size of the previous release artefacts.

If you want to see the results in action then you can wget (or curl) a binary from the GitHub release. For example, on a Raspberry Pi running Raspberry Pi OS (e.g. a pi hole) use the following commands (replace arm with x64 or arm64 as appropriate).

Download with wget (upper case O):

wget -O octoplot.xz https://github.com/jpsingleton/octoplot/releases/download/1.0.1/octoplot-linux-arm.xz

Or if you prefer curl (lower case o):

curl -L -o octoplot.xz https://github.com/jpsingleton/octoplot/releases/download/1.0.1/octoplot-linux-arm.xz

-L is required to follow the GitHub redirect to AWS S3.

Then decompress the binary, make it executable and run it.

xz -d octoplot.xz
chmod +x octoplot
./octoplot j

You should specify the region ID character for the area you are interested in. E.g. j for South East England, the default value is p (North Scotland). Add it to your PATH if you want to run octoplot from anywhere.

Install

If you want to build it for yourself then you can install .NET 5 with your usual package manager. Before you start using it you may want to disable the telemetry that is on by default. You can do this in many places, e.g. ~/.bashrc:

export DOTNET_CLI_TELEMETRY_OPTOUT=1

Or in /etc/environment (no need for the export command here) for wider reach:

DOTNET_CLI_TELEMETRY_OPTOUT=1

You can also alter your PATH here.

Background

I use my octoplot tool to help me plan when the cheapest time will be to run appliances. For example, when to set the timer on the oven for to be paid for it to pyrolytic auto-clean.

Our latest Agile bill from Octopus Energy put the average cost per kWh at about 8p, which is roughly half-price compared to fixed tariffs. This would save us over £300 a year if it continues.

You can use my Octoyosu tool to see how much you could save. If you want to switch then you can thank me (and save £50) by using this referral link.

Your mileage may vary (pun intended) as we have an EV (a second hand Leaf) that I typically charge overnight at weekends. I’ll save a follow-up review after a few more months of ownership for a future post but in summary it’s best car I’ve ever driven. It’s so much fun to drive and outrageously cheap to run but it still hasn’t stopped me from walking to the shops.

It’s not just about cost and it’s important to reduce usage too. I don’t want to be part of the problem.

I’ve finished reading Clearing the Air: The Beginning and the End of Air Pollution by Tim Smedley, which is excellent and well worth a read. Although EVs produce no exhaust emissions and produce less from brake wear, they still re-suspend pollution on the road produced by fossil cars. Sitting in traffic is the worst place to be from an exposure perspective, plus there’s the obvious additional negative health implications from lack of exercise.

Speaking of exercise, last weekend (as a lockdown project) I lagged the loft with insulation made from recycled glass, improving what was there already. As autumn leaves (fall) and winter arrives, this should help reduce our energy usage when the freezing temperatures come in December. It helped that I’m used to wearing a face mask now!


Would you like help solving a technology problem in your business?
Email me for a free consultation. I'm always open to new opportunities!

This blog is treeware! If you found it useful then please plant a tree.
Donate a treeDonate a tree🌳🌳