Avalonia can run an application directly in the browser thanks to WebAssembly: the .NET code is downloaded and executed by the browser, and the interface is drawn inside an area of the page.
One project, several targets
dotnet new avalonia.xplat -o Quotes
The cross-platform template creates a shared project with views and ViewModels and a "startup" project for each target: desktop, browser, Android and iOS. The browser project is very small:
internal sealed partial class Program
{
private static Task Main(string[] args) =>
BuildAvaloniaApp().StartBrowserAppAsync("out");
public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>();
}
The string "out" is the id of the HTML element in which the application is drawn.
When it makes sense
- Offering an online version of an existing desktop tool, for example a configurator or a technical calculator.
- Demos and free trials with no installation.
- Internal tools to be used even from workstations where software cannot be installed.
Limits to be aware of
- The first load downloads the runtime and the application: optimise it with trimming and compression.
- The code runs inside the browser sandbox: no free access to files and network, HTTP calls subject to CORS rules.
- For a public site indexed by search engines, server-generated HTML remains the right choice.
Used in the right place, it lets you reach users through the browser while reusing every last line of the desktop application's code.
Comments (0)
No comments yet.