MauiXamlSourceGenDemo
Sample code to demonstrate how to enable XAML Source Generation with .NET MAUI 10
Install / Use
/learn @jfversluis/MauiXamlSourceGenDemoREADME
MauiXamlSourceGenDemo
Check out the video walkthrough:
Sample code to demonstrate how to enable XAML Source Generation with .NET MAUI 10

How to enable?
- Make sure to use at least .NET MAUI 10 RC2 or up
- In your csproj add
<MauiXamlInflator>SourceGen</MauiXamlInflator> - Optionally, add
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>to show the generated code by the source generator- Note that on Windows this might generate compile errors when used from Visual Studio. In Visual Studio, this setting is not needed, just go to the Solution Explorer > your solution > your project > Dependencies > the TFM you're after for instance net10.0-android > Analyzers > Microsoft.Maui.Controls.SourceGen > Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator > the xsg files are the files with the source generated code.
- To overcome the build errors when enabling this you might want to also set
<CompilerGeneratedFilesOutputPath>C:\x</CompilerGeneratedFilesOutputPath>and make sure the path is the shorters path that is available on your machine. Make sure the folder exists.
Why use XAML Source Generation?
- Much faster debug builds
- Debug and release builds are more similar if not identical
- Step through your XAML code and debug
- Future-proof: for instance, we can now write Roslyn analyzers against our XAML code to warn you for common pitfalls
Have a look at the below table for the benchmark we did on the InitializeComponent() method on the Styles.xaml file for our new MAUI template including the sample content.

Related Skills
node-connect
339.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
