You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: ".NET MAUI XAML is compiled directly into intermediate language (IL) with the XAML compiler (XAMLC)."
4
-
ms.date: 02/24/2022
4
+
ms.date: 11/14/2025
5
5
---
6
6
7
-
# XAML compilation
7
+
# XAML Processing
8
8
9
-
.NET Multi-platform App UI (.NET MAUI) XAML is compiled directly into intermediate language (IL) with the XAML compiler (XAMLC). XAML compilation offers a number of benefits:
9
+
.NET Multi-platform App UI (.NET MAUI) XAML can be processed, and inflated into a tree of objects in different ways explained here. As of net10, default inflation is runtime for debug builds, XamlC (XamlCompilation) for Release. We encourage you to try source generation and use it if it works for you. This will become the future in new projects, then in all projects, soon.
10
+
11
+
## XAML Compilation
12
+
13
+
XAML is compiled directly into intermediate language (IL) with the XAML compiler (XAMLC). XAML compilation offers a number of benefits:
10
14
11
15
- It performs compile-time checking of XAML, notifying you of any errors.
12
16
- It removes some of the load and instantiation time for XAML elements.
@@ -17,51 +21,46 @@ XAML compilation is enabled by default in .NET MAUI apps. For apps built using t
17
21
> [!IMPORTANT]
18
22
> Compiled bindings can be enabled to improve data binding performance in .NET MAUI applications. For more information, see [Compiled Bindings](~/fundamentals/data-binding/compiled-bindings.md).
19
23
20
-
## Disable XAML compilation
21
-
22
-
XAML compilation can be disabled by passing `XamlCompilationOptions.Skip` to the <xref:Microsoft.Maui.Controls.Xaml.XamlCompilationAttribute>:
In this example, XAML compilation is disabled within the assembly, with XAML errors being reported at runtime rather than compile-time.
26
+
XAML can be inflated at Runtime using reflection. It has advantages, like allowing HotReload scenario, shortening build times, allow the report of diagnostics to IDE.
29
27
30
-
XAML compilation can also be disabled at the type level:
28
+
## XAML Sourcegeneration
31
29
32
-
```csharp
33
-
[XamlCompilation (XamlCompilationOptions.Skip)]
34
-
publicpartialclassMyPage : ContentPage
35
-
{
36
-
...
37
-
}
38
-
```
30
+
Starting with net10, XAML can be transformed into C# code at compilaiton time. It provides the following benefits:
39
31
40
-
In this example, XAML compilation is disabled only for the `MyPage` class.
32
+
- Consistency: same generated code used in Debug and Release
33
+
- Speed: inflation times on device are 10000% (100 times) faster in Debug, and 25% faster on Release. The volume of allocation is reduced in the same proportion
34
+
- Debug: you can see the generated code, you can break and debug it.
41
35
42
-
> [!WARNING]
43
-
> Disabling XAML compilation is not recommended because XAML is then parsed and interpreted at runtime, which will reduce app performance.
36
+
This is the recommended way going further. It will be enabled by default in the future.
44
37
45
-
## Enable XAML compilation
38
+
## Enable Source Generation, and per file settings
46
39
47
-
Because XAML compilation is enabled by default in .NET MAUI apps, removing any `XamlCompilation(XamlCompilationOptions.Skip)` statements will ensure that XAML compilation is enabled.
40
+
We no longer recommend using `[XamlCompilation]` attribute to enable or disable per file compilation.
48
41
49
-
Alternatively, XAML compilation can be forcibly enabled by passing `XamlCompilationOptions.Compile`to the <xref:Microsoft.Maui.Controls.Xaml.XamlCompilationAttribute>:
42
+
You can enable XAML source generation at the project level, by setting the `MauiXamlInflator` value to `SourceGen` in your csproj file as shown here:
In this example, XAML compilation is enabled for all of the XAML contained within the assembly, with XAML errors being reported at compile-time rather than runtime.
48
+
This will use source generation for both Release and Debug configurations.
56
49
57
-
XAML compilation can also be enabled at the type level:
50
+
You can revert to the default per file (or use wildcards) or force another inflator
<MauiXamlUpdate="MyFile.xaml"Inflator="SourceGen" /> <!-- enable sourcegen on a single file. prefer setting it at project level -->
55
+
<MauiXamlUpdate="Controls\**.xaml"Inflator="" /> <!-- revert to defaults for all xaml in Controls -->
56
+
<MauiXamlUpdate="Controls\**.xaml"Inflator="Runtime" /> <!-- force runtime inflation. if you have to do this, it probably indicates a bug in both XamlC and sourcegen, please report -->
57
+
</ItemGroup>
65
58
```
66
59
67
-
In this example, XAML compilation is enabled only for the `MyPage` class.
60
+
There other metadata you can set to instruct xaml sourcegenerator
61
+
62
+
```xml
63
+
<ItemGroup>
64
+
<MauiXamlUpdate="MyFile.xaml"Inflator="SourceGen"NoWarn="0612;0618" /> <!-- prevent the compiler to fail if the xaml use deprecated API -->
0 commit comments