Skip to content

Conversation

@simonrozsival
Copy link
Member

Description of Change

We must generate absolute file paths in #line directives. 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 Diagnostic instances reported by the source gen driver don't have the full paths.

This is the output of build compilation before and after the change:

# before
/Users/simonrozsival/Projects/playground/TestApp/obj/Debug/net10.0-android/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator/App.xaml(9,53): error CS1009: Unrecognized escape sequence

# after
/Users/simonrozsival/Projects/playground/TestApp/App.xaml(9,53): error CS1009: Unrecognized escape sequence

Issues Fixed

Fixes #31454

Copilot AI review requested due to automatic review settings September 8, 2025 12:43
@simonrozsival simonrozsival requested a review from a team as a code owner September 8, 2025 12:43
@simonrozsival simonrozsival added the area-xaml XAML, CSS, Triggers, Behaviors label Sep 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.NewLineInfo method to accept a ProjectItem instead of a string filename and use absolute paths
  • Added an AbsolutePath property to ProjectItem to expose the absolute file path
  • Updated all callers to pass the full ProjectItem instead of just the relative path
  • Added unit tests to verify the correct absolute path generation in #line directives

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

@simonrozsival simonrozsival enabled auto-merge (squash) September 11, 2025 12:22
@simonrozsival simonrozsival merged commit d82f913 into net10.0 Sep 11, 2025
148 checks passed
@simonrozsival simonrozsival deleted the dev/srozsival/fix-lineinfo-absolute-path branch September 11, 2025 12:25
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-xaml XAML, CSS, Triggers, Behaviors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants