Goal
Why this matters
Avalonia 11 targets .NET 8.0. The official repository pins versions in global.json:
| Scenario | SDK / Tooling | Notes |
|---|---|---|
| Desktop (Windows/macOS/Linux) | .NET SDK 8.0.x |
Use latest LTS; global.json ensures consistent builds across machines. |
| Android | .NET SDK 8.0.x + android workload |
Requires Android Studio or Visual Studio mobile workloads. |
| iOS/macOS Catalyst | .NET SDK 8.0.x + ios workload |
Requires Xcode CLI tools and Apple certificates for device deployment. |
| Browser (WebAssembly) | .NET SDK 8.0.x + wasm-tools workload |
Installs Emscripten toolchain for WASM builds. |
Run dotnet --list-sdks to confirm the expected SDK version is installed. When multiple SDKs coexist, keep a repo-level global.json to pin builds to the Avalonia-supported version.
winget install --id Microsoft.DotNet.SDK.8 (replace with the current LTS) and install the Windows Subsystem for Linux if you plan to test Linux packages.libEGL, libGLESv2, d3dcompiler_47) for broader GPU compatibility (see Chapter 26).brew install dotnet-sdk to keep versions updated.xcode-select --install).sudo apt install dotnet-sdk-8.0).sudo apt install libgtk-3-0 libwebkit2gtk-4.1-0) because the ControlCatalog sample relies on them.sudo apt install mesa-utils) and ICU libraries for globalization support.Verify your SDK installation:
dotnet --version dotnet --list-sdksMake sure the Avalonia-supported SDK (currently .NET 8.x for Avalonia 11) appears in the list before moving on.
Run these commands only if you plan to target additional platforms soon (you can add them later):
dotnet workload install wasm-tools # Browser (WebAssembly)
dotnet workload install android # Android toolchain
dotnet workload install ios # iOS/macOS Catalyst toolchain
dotnet workload install maui # Optional: Windows tooling support
# Restore workloads declared in a solution (after cloning a repo)
dotnet workload restore
If a workload fails, run dotnet workload repair and confirm your IDE also installed the Android/iOS dependencies (Android SDK Managers, Xcode command-line tools).
View -> Tool Windows -> Avalonia Previewer.dotnet watch tasks or use the Avalonia preview extension's Live Preview panel..vscode/tasks.json for dotnet run / dotnet watch to trigger builds with Ctrl+Shift+B."avalonia.preview.host" to dotnet in .vscode/settings.json so the previewer launches automatically when you open XAML files.dotnet new install Avalonia.Templates
This adds templates such as avalonia.app, avalonia.mvvm, avalonia.reactiveui, and avalonia.xplat.
Verify installation:
dotnet new list avalonia
You should see a table of available Avalonia templates.
| Template | Command | When to use |
|---|---|---|
| Desktop (code-behind) | dotnet new avalonia.app -n MyApp |
Small prototypes with code-behind patterns. |
| MVVM starter | dotnet new avalonia.mvvm -n MyApp.Mvvm |
Includes a ViewModel base class and sample bindings. |
| ReactiveUI | dotnet new avalonia.reactiveui -n MyApp.ReactiveUI |
If you standardise on ReactiveUI for MVVM. |
| Cross-platform heads | dotnet new avalonia.app --multiplatform -n MyApp.Multi |
Generates desktop, mobile, and browser heads in one project. |
| Split head projects | dotnet new avalonia.xplat -n MyApp.Xplat |
Separate desktop/mobile projects (Visual Studio friendly). |
| Control library | dotnet new avalonia.library -n MyApp.Controls |
Create reusable UI/control libraries. |
Pair this with dotnet workload list to confirm matching workloads are installed for the heads you create.
# Create a new solution folder
mkdir HelloAvalonia && cd HelloAvalonia
# Scaffold a desktop app template (code-behind pattern)
dotnet new avalonia.app -o HelloAvalonia.Desktop
cd HelloAvalonia.Desktop
# Restore packages and build
dotnet build
# Run the app
dotnet run
A starter window appears. Close it when done.
dotnet new avalonia.mvvm -o HelloAvalonia.Mvvm -> includes a ViewModel base class and data-binding sample.dotnet new avalonia.reactiveui -o HelloAvalonia.ReactiveUI -> adds ReactiveUI integration out of the box.dotnet new avalonia.app --multiplatform -o HelloAvalonia.Multi -> single-project layout with mobile/browser heads.dotnet new avalonia.xplat -o HelloAvalonia.Xplat -> generates separate head projects (desktop/mobile) suited to Visual Studio.dotnet new avalonia.library -o HelloAvalonia.Controls -> starts a reusable control/library project.HelloAvalonia.Desktop.csproj.MainWindow.axaml while the app runs.code . inside the project directory.launch.json and .vscode/tasks.json.HelloAvalonia.Desktop.csproj: project metadata--target frameworks, NuGet packages, Avalonia build tasks (Avalonia.Build.Tasks compiles XAML to BAML-like assets; see CompileAvaloniaXamlTask.cs).Program.cs: entry point returning BuildAvaloniaApp(). Calls UsePlatformDetect, UseSkia, LogToTrace, and starts the classic desktop lifetime (definition in AppBuilderDesktopExtensions.cs).App.axaml / App.axaml.cs: global resources and startup logic. App.OnFrameworkInitializationCompleted creates and shows MainWindow (implementation defined in Application.cs).MainWindow.axaml / .axaml.cs: your initial view. XAML is loaded by AvaloniaXamlLoader.Assets/ and Styles/: sample resource dictionaries you can expand later.
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="HelloAvalonia.MainWindow"
Width="400" Height="260"
Title="Hello Avalonia!">
<StackPanel Margin="16" Spacing="12">
<TextBlock Text="It works!" FontSize="24"/>
<Button Content="Click me" HorizontalAlignment="Left"/>
</StackPanel>
</Window>
Rebuild and run (dotnet run or IDE Run) to confirm the change.
dotnet command missing: reinstall the .NET SDK and restart the terminal/IDE. Confirm environment variables (PATH) include the dotnet installation path.dotnet new install Avalonia.Templates or remove outdated versions with dotnet new uninstall Avalonia.Templates.dotnet nuget locals all --clear), ensure internet access or configure an offline mirror, then rerun dotnet restore.dotnet workload repair. Ensure Visual Studio or Xcode installed the matching tooling.libmesa, libx11-dev).SKIA_SHARP_GPU=0) to isolate driver issues, then update GPU drivers or include ANGLE fallbacks.https://www.myget.org/F/avalonia-nightly/api/v3/index.json to NuGet sources to test nightly builds; pin a stable package before release.git clone https://github.com/AvaloniaUI/Avalonia.git.git submodule update --init --recursive..\build.ps1 -Target Build../build.sh --target=Build.dotnet run --project samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj.Building from source gives you binaries with the latest commits, useful for testing fixes or contributing.
dotnet --list-sdks and dotnet workload list. If workloads are missing, run dotnet workload restore../build.sh --target=Build or .\build.ps1 -Target Build), and run the ControlCatalog sample.samples/ControlCatalog/ControlCatalog.csproj and map referenced Avalonia packages to their source folders. Update your architecture sketch with these relationships.App.axaml.cs (OnFrameworkInitializationCompleted) and step through startup to watch the lifetime initialise.App.OnFrameworkInitializationCompleted live and what does it do?What's next