This is the shortest path from an Avalonia project to generated AXSG output. It assumes you want the standard application-facing integration path, not a custom SDK or tooling-host composition.
For most applications:
<PackageReference Include="XamlToCSharpGenerator" Version="x.y.z" />
If your repo already has custom SDK logic, generator composition rules, or a non-standard runtime host, stop here and read Package Selection and Integration. The umbrella package is the right default for app projects, but it is not the only supported integration model.
AXSG does not silently replace Avalonia's default backend. Opt into the generated compiler path explicitly:
<PropertyGroup>
<AvaloniaXamlCompilerBackend>SourceGen</AvaloniaXamlCompilerBackend>
</PropertyGroup>
If you need a custom project item group, set XamlSourceGenInputItemGroup and mirror your @(AvaloniaXaml) items into that group. Do not override XamlSourceGenAdditionalFilesSourceItemGroup for Avalonia applications; AXSG always projects Avalonia XAML into AdditionalFiles as AvaloniaXaml.
Register the AXSG runtime loader on AppBuilder:
using XamlToCSharpGenerator.Runtime;
public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseAvaloniaSourceGeneratedXaml();
InitializeComponent patternsIf a class-backed view or theme already has:
private void InitializeComponent()
{
global::Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this);
}
do not leave that method unconditional after enabling AXSG. AXSG generates InitializeComponent(bool loadXaml = true) for class-backed XAML, and the hand-written parameterless overload will intercept InitializeComponent(); calls in constructors.
Use one of these approaches:
#if !AXAML_SOURCEGEN_BACKEND for mixed-backend or multi-target projectsThe full behavior, including overload resolution and build constants, is documented in:
Add x:DataType to views, templates, and themes where you want compiled binding semantics:
<UserControl
x:Class="MyApp.Views.MainView"
x:DataType="vm:MainViewModel">
Do this consistently in:
DataTemplate scopesAXSG can still compile some scenarios without x:DataType, but that is no longer the strongest validation path. The best diagnostics, completion, navigation, and inlay-hint behavior all assume explicit type scopes where the XAML feature allows them.
Run a normal build first:
dotnet build
This lets AXSG generate code, surface diagnostics, and register the runtime artifacts used by later tooling.
After the first successful build, inspect obj/<Configuration>/<TFM>/ once. AXSG is intentionally inspectable. Confirming that generated partials and helper code exist is the fastest way to separate package/build issues from authored-XAML issues.
At this point you should be able to:
If any of those are missing, move to Troubleshooting before adding more features. Most downstream editor and hot-reload problems are much easier to diagnose once the base compiler/runtime path is known-good.
Once the basic path works, use the sample catalog to validate more advanced features:
Before migrating a larger application, prove one feature from each layer:
That confirms the compiler, runtime, and tooling surfaces are all present and aligned.
In a healthy AXSG setup you should see:
InitializeComponent methods for class-backed documentsIf the generated output shape looks wrong, start with the build/package docs before assuming the XAML syntax is at fault.