[XSG] enable/disable feature in msbuild#31349
Merged
StephaneDelcroix merged 10 commits intonet10.0from Sep 1, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a configuration option to disable the generation of #line directives in XAML source generation, making the generated C# files more readable for debugging and development purposes without affecting the final compiled IL.
Key Changes
- Adds
EnableLineInfoproperty to control#linedirective generation - Removes conditional compilation attributes in favor of runtime configuration
- Updates test project to disable line info generation by default
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Controls.Xaml.UnitTests.csproj | Removes _MAUIXAML_SG_SOURCEINFO define constant to disable line info in tests |
| SetPropertiesVisitor.cs | Updates property setting code to conditionally generate line info based on context |
| SourceGenContext.cs | Adds EnableLineInfo boolean property to control line info generation |
| ProjectItem.cs | Adds EnableLineInfo property with default value of true |
| PrePost.cs | Refactors line info generation from conditional compilation to runtime control |
| InitializeComponentCodeWriter.cs | Sets EnableLineInfo from project item configuration |
| GeneratorHelpers.cs | Adds parsing of LineInfo metadata to determine if line info should be enabled |
afd7132 to
dcf0104
Compare
...ontrols/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets
Outdated
Show resolved
Hide resolved
9fff4ba to
f5cb6b5
Compare
simonrozsival
previously approved these changes
Aug 28, 2025
Doesn't change the generated IL at the end, but make the generated cs file easir to read, understand, reflect on
<MauiXamlEnableDiagnostics> property or EnableDiagnostics item metadata. defaults to true for debug
24ccb76 to
b0be23e
Compare
| <!-- Assign the default inflator to MauiXaml that don't have any --> | ||
| <!-- there's a roslyn bug that stops parsing value at the first semicolon. replace them all https://github.com/dotnet/roslyn/issues/43970 --> | ||
| <MauiXaml Inflator="$([MSBuild]::ValueOrDefault('%(MauiXaml.Inflator)','$(_MauiXamlInflator)').Replace(';', ','))"/> | ||
| <MauiXaml NoWarn="$([MSBuild]::ValueOrDefault('%(MauiXaml.NoWarn)','').Replace(';', ','))"/> |
Contributor
Author
There was a problem hiding this comment.
you know, that roslyn bug...
jonathanpeppers
approved these changes
Aug 29, 2025
Comment on lines
+14
to
+16
| <EnableMauiXamlDiagnostics Condition=" '$(EnableMauiXamlDiagnostics)' == '' ">$(EnableMauiDiagnostics)</EnableMauiXamlDiagnostics> | ||
| <EnableMauiXamlDiagnostics Condition=" '$(EnableMauiXamlDiagnostics)' == '' And '$(Configuration)' == 'Debug' ">$(EnableDiagnostics)</EnableMauiXamlDiagnostics> | ||
| <EnableMauiXamlDiagnostics Condition=" '$(EnableMauiXamlDiagnostics)' == '' And '$(Configuration)' == 'Debug' ">true</EnableMauiXamlDiagnostics> |
Member
There was a problem hiding this comment.
These defaults make sense, as I don't think we want $(EnableDiagnostics) to default to true in the iOS/Android workloads.
Contributor
Author
There was a problem hiding this comment.
y, I like those defaults as well
simonrozsival
approved these changes
Sep 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
enable/disable visualdiagnostics, enable/disable #line pragmas, no warn per file
global properties:
<EnableMauiXamlDiagnostics>true|false</EnableMauiXamlDiagnostics >. defaults to true for Debug configuration<MauiXamlLineInfo>enable|disable</MauiXamlLineInfo>defaults to 'enable'<MauiXamlNoWarn>0618;0612</MauiXamlNoWarn>per MauiXaml item metadata
EnableDiagnostics="true|false"
LineInfo="disable|enable"
NoWarn="0618"
user shouldn't have to set those properties, but it greatly helps the readability of the generated file