This document contains development-focused instructions for iterating on the XamlToCSharpGenerator (AXSG) locally. It is intended for developers debugging the generator and testing it against a more complex sample.
Use this when you want to iterate on the generator itself and test changes locally.
-
Clone or have the local checkout of the AXSG repository available, e.g.
/Users/lextm/vscode-axaml/src/XamlToCSharpGenerator. -
Wire the build-time props/targets into your sample project (dev convenience):
<!-- conditionally import buildTransitive props/targets from local checkout -->
<Import Project="../path/to/XamlToCSharpGenerator/src/XamlToCSharpGenerator.Build/buildTransitive/XamlToCSharpGenerator.Build.props"
Condition="Exists('../path/to/XamlToCSharpGenerator/src/XamlToCSharpGenerator.Build/buildTransitive/XamlToCSharpGenerator.Build.props')" />
<!-- set the backend and point at the local analyzer project for analyzer orchestration -->
<PropertyGroup>
<AvaloniaXamlCompilerBackend>SourceGen</AvaloniaXamlCompilerBackend>
<AvaloniaSourceGenCompilerEnabled>true</AvaloniaSourceGenCompilerEnabled>
<XamlSourceGenLocalAnalyzerProject>../path/to/XamlToCSharpGenerator/src/XamlToCSharpGenerator.Generator/XamlToCSharpGenerator.Generator.csproj</XamlSourceGenLocalAnalyzerProject>
</PropertyGroup>- Build the AXSG repo (so analyzer DLLs exist):
cd /path/to/XamlToCSharpGenerator
dotnet restore
dotnet build -c Debug- (Optional) Add direct
Analyzeritems to the sample project to point to the built generator DLLs (helpful during dev):
<ItemGroup Condition="Exists('../path/to/XamlToCSharpGenerator/src/XamlToCSharpGenerator.Generator/bin/Debug/netstandard2.0/XamlToCSharpGenerator.Generator.dll')">
<Analyzer Include="../path/to/XamlToCSharpGenerator/src/XamlToCSharpGenerator.Generator/bin/Debug/netstandard2.0/XamlToCSharpGenerator.Generator.dll" />
<!-- add other required dependency DLLs from the local build output as needed -->
</ItemGroup>- Add a
ProjectReferenceto the runtime helper (soUseAvaloniaSourceGeneratedXamlis available):
<ItemGroup>
<ProjectReference Include="../path/to/XamlToCSharpGenerator/src/XamlToCSharpGenerator.Runtime.Avalonia/XamlToCSharpGenerator.Runtime.Avalonia.csproj" />
</ItemGroup>- Build the sample. If everything is wired correctly, the generator should run and produce the generated partials (e.g.,
InitializeComponentwill be available at compile time):
dotnet build -c DebugOptional: During active generator development it can be helpful to pack the local generator into a local nupkg and reference that from the sample for a more stable dev loop.
Troubleshooting (local-analyzer specific)
InitializeComponentmissing is often caused by the source generator not running because the analyzer failed to load (TargetInvocationException). If you see analyzer load errors:- Prefer using the published NuGet
XamlToCSharpGeneratorpackage while debugging loader issues. - If using the local checkout, ensure you built the generator and all its dependency projects first and add all required DLLs as
Analyzerentries or useXamlSourceGenLocalAnalyzerProject+ import the build transitive props/targets. - Run the build with detailed logging to capture analyzer exceptions:
- Prefer using the published NuGet
dotnet build -c Debug -v:detailedIf you prefer a stable dev loop, pack the local generator into a local nupkg and reference it from the sample.