Running in the Browser
It is currently very early days and not ready for production, however if you want to test this exciting new feature please take the following steps.
- Install
wasm-experimental
andwasm-tools
workload tools. See dotnet documentation.
dotnet workload install wasm-experimental wasm-tools
- Install or update the dotnet templates to the latest version.
dotnet new install avalonia.templates
- Create a new directory for the project.
mkdir WebTest
cd WebTest
- Generate a new project that supports running in the browser.
dotnet new avalonia.xplat
- In order to run simply do:
cd WebTest.Browser
dotnet run
- In the console output you will see HTTP and HTTPS links to open the app.
Interop
It is possible to call JavaScript code from the Avalonia Web application. Avalonia app is compatible with standard [JSImport]/[JSExport] interop from Microsoft. You can find more information on their documentation.
Legacy Blazor backend
Starting from Avalonia 11.0 Avalonia.Web package relies on build-in .NET interop with better stability and performance. Legacy Blazor backend is still available for compatability and can be referenced using Avalonia.Web.Blazor package.
Troubleshooting
If you have not performed the step to install required workloads, you will encounter errors when running the app in your browser later (e.g. System.DllNotFoundException: libSkiaSharp
) and you will need to rebuild again before the app will run.