Member-only story

Cross-Platform Development in .NET 8: Build Once, Run Everywhere

Semih Tekin
2 min readDec 24, 2024

--

The promise of .NET has always been its ability to run applications on any platform, and .NET 8 takes this vision further by enhancing support for cross-platform development through MAUI (Multi-platform App UI) and WebAssembly. In this article, we’ll examine the tools and techniques .NET 8 provides for building truly platform-agnostic applications.

Cross-Platform Features in .NET 8

1. MAUI (Multi-platform App UI)

MAUI simplifies cross-platform development by providing a unified framework for building mobile, desktop, and tablet applications.

Example: Building a Simple MAUI Application

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
Content = new Label
{
Text = "Hello, .NET 8!",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
}
}

The same code runs seamlessly on Android, iOS, macOS, and Windows.

2. WebAssembly (WASM) Integration

.NET 8 enhances WASM integration, enabling developers to run full-fledged .NET applications in the browser without additional plugins.

Example: Calling JavaScript from .NET in Blazor WASM

var jsRuntime = (IJSInProcessRuntime)JSRuntime;
string userAgent = jsRuntime.Invoke<string>("navigator.userAgent");
Console.WriteLine($"User Agent: {userAgent}");

This allows developers to mix .NET and JavaScript for powerful web applications.

.NET 8 provides a robust toolkit for cross-platform development, allowing developers to target multiple platforms with a single codebase. Its improvements in MAUI and WASM make it easier than ever to create versatile applications.

--

--

Semih Tekin
Semih Tekin

No responses yet

Write a response