In from the cold

Finally making Linux and .NET get along

Alistair Chapman

@agc93

Who am I?

Alistair Chapman

 

agc93

 

agc93

.NET MVP

Senior Cloud Security Engineer @ Red Hat

Walking, talking case of impostor syndrome

The Plan

(likely going to be abandoned about 5 minutes in)

  • History Lesson
  • The Tale of Two Platforms
  • Building .NET apps for Linux
  • Bridging the platform gap

The History Lesson

We've been here before...

(or why the Linux community looks at .NET like an aggressive leper)

A history of cross-platform .NET

The Tale of Two Platforms

Assert.AreNotEqual(".NET Core", "Mono");

Building .NET apps for Linux

  • Preparing your environment
  • Building your app
  • Test, package, bundle
  • Deployment and running

Building .NET apps for Linux

Preparing your environment

Building .NET apps for Linux

Preparing your environment

(this time like its 2019)

Building .NET apps for Linux

Building your app

Building .NET apps for Linux

Test, package and bundle your app

Deployment and Operations

  • .NET Core has separate runtime and SDK
    • Build requires SDK
    • FDD requires runtime
    • SCD requires only dependencies!
  • .NET Core 3.0 includes drastically better Linux support
    • and distro-portable deployments!
    • also support musl-based distros

Deployment and Operations

(but way better this time)

  • .NET Core 3.0 natively supports single-file output
    • One line in the csproj!
  • .NET Core 3.0 also includes experimental assembly trimming
  • Warp can also package applications into a single package

Deployment and Operations

(ASP.NET Core apps)

  • Each app uses an isolated server process
  • Kestrel is included out-of-the-box
  • Apps can be managed and monitored with systemd
[Unit]
Description=Example .NET Web API Application running on Ubuntu

[Service]
WorkingDirectory=/var/aspnetcore/
ExecStart=/usr/bin/dotnet /path/to/mvc/app.dll
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

Deployment and Operations

(ASP.NET Core apps)

  • .NET Core 3.0 workers natively support systemd!
  • Use to better integrate long-running apps (i.e. servers)
[Unit]
Description=Worker app

[Service]
Type=notify
ExecStart=/usr/sbin/my-worker-app

[Install]
WantedBy=multi-user.target

Linux for Windows Developers

A simple survival guide

https://xkcd.com/272/

Important rules of the Linux world

Everything makes perfect sense

Nothing makes any sense

Bridging the Platform Gap

Making Linux a first-class .NET platform

Bridging the platform gap

  • Basically every supported distro uses DBus
  • Perfect for inspecting and controlling hardware/OS
  • Tmds.Dbus provides C# API
  • Can also be used to control systemd services
    • (requires some Polkit changes)

Connecting and controlling the underlying platform

Bridging the platform gap

Unsolicited advice for library authors

  • Always target netstandard*
  • Test on multiple distros
  • Be aware of logging
  • If possible, set up xplat CI/CD
  • Be open/gentle with collaborators
  • Seek help!

Alistair Chapman

@agc93

(essentially everywhere)

 

 

https://agchapman.com/talks

https://blog.agchapman.com/