[XSG] Use absolute file paths when generating #line#31519
Merged
simonrozsival merged 6 commits intonet10.0from Sep 11, 2025
Merged
[XSG] Use absolute file paths when generating #line#31519simonrozsival merged 6 commits intonet10.0from
simonrozsival merged 6 commits intonet10.0from
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the generation of #line directives in the MAUI source generator to use absolute file paths instead of relative paths. Relative paths in #line directives have undefined behavior according to the Roslyn compiler, causing issues with error reporting that shows incorrect file paths in the build output.
Key changes:
- Modified the
PrePost.NewLineInfomethod to accept aProjectIteminstead of a string filename and use absolute paths - Added an
AbsolutePathproperty toProjectItemto expose the absolute file path - Updated all callers to pass the full
ProjectIteminstead of just the relative path - Added unit tests to verify the correct absolute path generation in
#linedirectives
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Controls/src/SourceGen/PrePost.cs |
Modified to use absolute paths in #line directives by accepting ProjectItem parameter |
src/Controls/src/SourceGen/ProjectItem.cs |
Added AbsolutePath property and refactored to store AdditionalText reference |
src/Controls/src/SourceGen/Visitors/SetPropertiesVisitor.cs |
Updated calls to pass ProjectItem instead of relative path string |
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/LineInfoTests.cs |
New test class to verify absolute paths in generated #line directives |
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SourceGenXamlInitializeComponentTests.cs |
Updated test helper to use absolute paths for consistent test behavior |
StephaneDelcroix
previously approved these changes
Sep 8, 2025
StephaneDelcroix
approved these changes
Sep 11, 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
We must generate absolute file paths in
#linedirectives. Using relative paths in this context is not supported (dotnet/roslyn#71202 (comment)).I introduced a sourcegen test but I'm not sure if this is the best way to test it. The
Diagnosticinstances reported by the source gen driver don't have the full paths.This is the output of build compilation before and after the change:
Issues Fixed
Fixes #31454