| title |
|---|
Configuration Model |
This document describes the unified configuration model used by XamlToCSharpGenerator.
Configuration is merged from these sources:
- Built-in defaults.
- File source (
xaml-sourcegen.config.jsonin project root, and explicit AdditionalFiles with the same file name). - MSBuild source (
build_property.*options). - Code source (
[assembly: AssemblyMetadata(...)]).
Default precedence values:
| Source | Default precedence |
|---|---|
| Project-default config file | 90 |
| Explicit config file AdditionalFiles | 100 |
| MSBuild | 200 |
| Code | 300 |
Higher precedence wins when multiple sources set the same value.
Set XamlSourceGenConfigurationPrecedence (or compatibility alias AvaloniaSourceGenConfigurationPrecedence) in MSBuild:
<PropertyGroup>
<XamlSourceGenConfigurationPrecedence>ProjectDefaultFile=90;File=100;MsBuild=200;Code=300</XamlSourceGenConfigurationPrecedence>
</PropertyGroup>Supported keys:
ProjectDefaultFileFileMsBuildCode
Aliases for ProjectDefaultFile are also accepted: ProjectDefault, DefaultFile.
Invalid segments produce warning AXSG0933.
File name:
xaml-sourcegen.config.json
The parser accepts JSON comments and trailing commas.
schemaVersion is optional; when specified it must currently be 1 (otherwise warning AXSG0917).
Top-level sections:
buildparsersemanticContractbindingemittertransformdiagnosticsframeworkExtras
Unknown keys are ignored. Known keys with invalid value shape produce AXSG0918-AXSG0927 warnings.
| Key | Type |
|---|---|
isEnabled |
bool |
backend |
string |
strictMode |
bool |
hotReloadEnabled |
bool |
hotReloadErrorResilienceEnabled |
bool |
ideHotReloadEnabled |
bool |
hotDesignEnabled |
bool |
iosHotReloadEnabled |
bool |
iosHotReloadUseInterpreter |
bool |
dotNetWatchBuild |
bool |
buildingInsideVisualStudio |
bool |
buildingByReSharper |
bool |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
allowImplicitXmlnsDeclaration |
bool |
implicitStandardXmlnsPrefixesEnabled |
bool |
implicitDefaultXmlns |
string |
inferClassFromPath |
bool |
implicitProjectNamespacesEnabled |
bool |
globalXmlnsPrefixes |
object<string,string> |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
typeContracts |
object<string,string> |
propertyContracts |
object<string,string> |
eventContracts |
object<string,string> |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
useCompiledBindingsByDefault |
bool |
cSharpExpressionsEnabled |
bool |
implicitCSharpExpressionsEnabled |
bool |
markupParserLegacyInvalidNamedArgumentFallbackEnabled |
bool |
typeResolutionCompatibilityFallbackEnabled |
bool |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
createSourceInfo |
bool |
tracePasses |
bool |
metricsEnabled |
bool |
metricsDetailed |
bool |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
rawTransformDocuments |
object<string,string> |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
treatWarningsAsErrors |
bool |
severityOverrides |
object<string,Info|Warning|Error|null> |
additionalProperties |
object<string,string> |
| Key | Type |
|---|---|
sections |
object<sectionName, object<string,string>> |
additionalProperties |
object<string,string> |
{
"schemaVersion": 1,
"build": {
"isEnabled": true,
"backend": "SourceGen",
"strictMode": true
},
"parser": {
"allowImplicitXmlnsDeclaration": true,
"implicitDefaultXmlns": "https://github.com/avaloniaui",
"globalXmlnsPrefixes": {
"vm": "using:Demo.ViewModels"
}
},
"binding": {
"useCompiledBindingsByDefault": true
},
"diagnostics": {
"severityOverrides": {
"AXSG0113": "Info"
}
}
}Use assembly metadata keys with prefix XamlSourceGen.:
using System.Reflection;
[assembly: AssemblyMetadata("XamlSourceGen.Build.Backend", "SourceGen")]
[assembly: AssemblyMetadata("XamlSourceGen.Build.IsEnabled", "true")]
[assembly: AssemblyMetadata("XamlSourceGen.Binding.UseCompiledBindingsByDefault", "true")]
[assembly: AssemblyMetadata("XamlSourceGen.Parser.GlobalXmlnsPrefixes.vm", "using:Demo.ViewModels")]Section/key names are case-insensitive. Invalid keys/values produce warnings AXSG0930-AXSG0932.