xaml-csharp-development-skill-for-avalonia

MSBuild, XAML Compilation, and AOT Tooling

Key Build Pipeline Facts

From Avalonia package/build targets:

NativeAOT/Trimming-Oriented Project Baseline

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>

    <!-- Avalonia + XAML -->
    <EnableAvaloniaXamlCompilation>true</EnableAvaloniaXamlCompilation>
    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>

    <!-- NativeAOT -->
    <PublishAot>true</PublishAot>
    <TrimMode>full</TrimMode>
    <InvariantGlobalization>true</InvariantGlobalization>
  </PropertyGroup>
</Project>

Adjust runtime and trim settings per product requirements, but keep compiled bindings and compiled XAML as baseline.

Source Generator Controls (Avalonia.Generators.props)

Available knobs:

Use:

Packaging and Resource Item Rules

Symptoms of misconfiguration:

AOT Risk APIs to Review Explicitly

Treat these as design decisions, not defaults:

Build Verification Checklist

XAML-First and Code-Only Usage

Default mode:

XAML-first references:

Code-only alternative (on request):

var view = new StackPanel
{
    Children =
    {
        new TextBlock { Text = "AOT-safe baseline" },
        new Button { Content = "Run" }
    }
};

window.Content = view;