Development on Linux of .NET Applications

Rainer Stropek | time cockpit

Linux for .NET Dev

Options

  • Linux on your PC or in a VM (on-premises or cloud) πŸ”—
    • Supported distros/OS versions for .NET πŸ”—
    • Installation types πŸ”—Β (manual, Snap, scripted)
    • ⚠️ Before switching, verify that all required apps are available
  • Containerized environment (Docker)
    • Independent of host OS (with Docker Desktop)
    • No installation/update required
    • .NET on docker hub πŸ”—
  • Cloud development environments
    • E.g. GitHub Codespaces, gitpod
  • Windows Subsystem for Linux (WSL 2) πŸ”—
    • Linux environment on Windows without VM or dual-boot
    • My personal favorite

WSL 2

  • Windows and Linux kernels run side-by-side
    • Linux kernel nicely integrated with Windows
      (e.g. file system access, running apps with/without GUI)
    • systemdΒ support πŸ”—
    • USB support via USBIPD πŸ”—
  • Option: Get Linux distros from Windows Store
    • You can also import/create other distros
  • Use WSL as backend for Docker Desktop πŸ”—
    • Better performance than VM
  • Enterprise-readiness πŸ”—
  • Tip: Combine with Windows Terminal πŸ”—

WSL Demos

IDE Options

IDE Options on/for Linux

  • IDE on Linux
    • VSCode and VSCode Forks (e.g. Cursor AI)
    • JetBrains Rider πŸ”—
    • Any other editor with support for .NET LSP (e.g. Neovim)
  • Visual Studio on Windows + Debug in container
    • Docker support in Visual Studio
    • Not my personal favorite
  • Remote Development with VSCode and forks πŸ”—
    • SSH, containers, WSL, GitHub Codespaces
    • My personal favorite

Remote Development Demos

.NET on Linux

.NET on Linux

  • Linux support in .NET since .NET Core
    • Good Linux support in recent .NET versions
  • Target frameworks for .NET πŸ”—
    • TFM = Target Framework Moniker
    • Portable vs. OS-specific
    • Use multiple TFMs if applicable πŸ”—
  • .NET Runtime Identifier πŸ”—
    • Identify target platform (e.g. linux-x64)
    • E.g. used when building platform-specific executables

Publishing Demos

Tips for Cross-Platform Development

Tips

  • Avoid exploiting platform-specific behaviors. Examples:
    • Case-insensitive file names on Windows
  • Write platform-independent code. Examples:
    • Use PathΒ to combine folder names
    • Use Environment.NewLine
    • Use UTF-8 encoding for text files
    • Use Environment.GetFolderPath to get special folders
  • Avoid platform-specific features. Examples:
    • Configuration files or environment variables instead of Windows Registry
    • gRPC over Sockets instead of Windows Named Pipes
    • Open TelemetryΒ instead of Windows Event Log

Tips

  • Be aware of platform specifics. Examples:
    • Higher path length limit on Linux
    • File permissions work differently on Windows and Linux
    • Symbolic links on Linux
    • Consider platform-specific implementations via DI
  • Avoid platform-specific UI technologies
    • Avalonia or MAUI for desktop apps
    • Web UI
  • Use cross-platform script platform for automation tasks
    • TypeScript instead of bash
    • PowerShell on Linux

Tips (Skills)

  • Get foundational knowledge about Linux
    • Basic commands, package management, Linux monitoring tools, networking fundamentals, etc.
  • Become familiar with dotnet-related CLIs
    • Frequently used when developing on Linux
  • Containers are important on Linux
    • Get familiar with Docker or similar technology

Q&A

Rainer Stropek | time cockpit