Skip to content

Fix UWP XBF files losing subdirectory paths in resources.pri when UseArtifactsOutput is enabled#53867

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-xbf-subdirectory-paths
Open

Fix UWP XBF files losing subdirectory paths in resources.pri when UseArtifactsOutput is enabled#53867
Copilot wants to merge 4 commits intomainfrom
copilot/fix-xbf-subdirectory-paths

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

When UseUwp=true and UseArtifactsOutput=true, the IntermediateOutputPath moves outside the project directory. The AppX Package Targets compute PRI paths for _GeneratedXbfFiles using %(Filename)%(Extension) for items outside the project directory, dropping subdirectory prefixes (e.g., Styles.xbf instead of Resources\Styles.xbf), causing runtime XamlParseException.

Changes

  • Microsoft.NET.Windows.targets: Adds _FixGeneratedXbfFilesLink target that runs AfterTargets="MarkupCompilePass2" when UseUwp=true. For any _GeneratedXbfFiles item outside the project directory (the artifacts case), sets Link to the path relative to $(IntermediateOutputPath):
<Target Name="_FixGeneratedXbfFilesLink"
        AfterTargets="MarkupCompilePass2"
        Condition="'$(UseUwp)' == 'true'">
  <PropertyGroup>
    <_NormalizedIntermediateOutputPath>$([MSBuild]::EnsureTrailingSlash($([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)'))))</_NormalizedIntermediateOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <_GeneratedXbfFiles Update="@(_GeneratedXbfFiles)"
      Condition="'%(Link)' == '' and !%(FullPath).StartsWith(ProjectDirectory)">
      <Link>$([MSBuild]::MakeRelative($(_NormalizedIntermediateOutputPath), %(FullPath)))</Link>
    </_GeneratedXbfFiles>
  </ItemGroup>
</Target>

This ensures Resources\Styles.xbf is correctly emitted into resources.pri rather than just Styles.xbf, matching what the XAML compiler-generated code-behind references via ms-appx:///Resources/Styles.xaml.

  • GivenThatWeWantToBuildAWindowsDesktopProject.cs: Adds regression test ItSetsCorrectLinkMetadataOnGeneratedXbfFilesWhenUsingArtifactsOutput that creates a UWP project with UseArtifactsOutput=true, injects simulated _GeneratedXbfFiles items in subdirectories of $(IntermediateOutputPath), and verifies that the _FixGeneratedXbfFilesLink target correctly sets Link metadata to preserve the subdirectory structure (e.g., Resources\Styles.xbf and Views\Home.xbf).

Copilot AI and others added 2 commits April 14, 2026 20:51
…ArtifactsOutput is enabled

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/4d3dd462-6363-4288-8aca-ceaf03eb3e26

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
… PropertyGroup

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/4d3dd462-6363-4288-8aca-ceaf03eb3e26

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix UWP XBF files losing subdirectory paths in resources.pri Fix UWP XBF files losing subdirectory paths in resources.pri when UseArtifactsOutput is enabled Apr 14, 2026
Copilot AI requested a review from marcpopMSFT April 14, 2026 20:52
@marcpopMSFT marcpopMSFT marked this pull request as ready for review April 14, 2026 20:57
@marcpopMSFT marcpopMSFT requested review from baronfel and Copilot April 14, 2026 20:57
@marcpopMSFT
Copy link
Copy Markdown
Member

@copilot can you add a test for this?

Copy link
Copy Markdown
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

Fixes incorrect resource path computation for UWP-generated XBF files when UseArtifactsOutput=true moves IntermediateOutputPath outside the project directory, preventing subdirectory paths from being dropped in resources.pri.

Changes:

  • Adds a new MSBuild target (_FixGeneratedXbfFilesLink) that runs after MarkupCompilePass2 for UseUwp=true.
  • For _GeneratedXbfFiles outside the project directory, sets Link to the path relative to $(IntermediateOutputPath) to preserve subdirectory structure.

…tput is enabled

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/89b95d8b-f70d-4b67-9b72-de499eb167cc

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot can you add a test for this?

Added a regression test in commit c51802b: ItSetsCorrectLinkMetadataOnGeneratedXbfFilesWhenUsingArtifactsOutput in GivenThatWeWantToBuildAWindowsDesktopProject.cs.

The test creates a UseUwp=true project with UseArtifactsOutput=true (via Directory.Build.props), injects fake _GeneratedXbfFiles items in subdirectories of $(IntermediateOutputPath) (simulating what the XAML compiler produces), and verifies that _FixGeneratedXbfFilesLink sets the correct Link metadata preserving subdirectory paths (e.g., Resources\Styles.xbf instead of just Styles.xbf).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UWP XBF files lose subdirectory paths in resources.pri when UseArtifactsOutput is enabled

3 participants