Skip to content

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

Merged
marcpopMSFT merged 5 commits into
mainfrom
copilot/fix-xbf-subdirectory-paths
Jul 30, 2026
Merged

Fix UWP XBF files losing subdirectory paths in resources.pri when UseArtifactsOutput is enabled#53867
marcpopMSFT merged 5 commits into
mainfrom
copilot/fix-xbf-subdirectory-paths

Conversation

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

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 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?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

@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).

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fix seemed reasonable when I looked at it last week - good analysis from Copilot and a better resolution than the one I originally suggested.

@marcpopMSFT
marcpopMSFT force-pushed the copilot/fix-xbf-subdirectory-paths branch 2 times, most recently from 0d45159 to 19177e5 Compare May 19, 2026 18:51
@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot test ItSetsCorrectLinkMetadataOnGeneratedXbfFilesWhenUsingArtifactsOutput is failing because of this change. Please fix:

[xUnit.net 00:01:08.51]       C:\h\w\A2410948\p\d\sdk\11.0.100-ci\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Windows.targets(401,5): error MSB4096: The item "C:\h\w\A2410948\t\dotnetSdkTests\wlal550e.tx3\ItSetsCorrect---81D5B905\artifacts\obj\UwpXbfLinkTest\debug\Resources\Styles.xbf" in item list "_GeneratedXbfFiles" does not define a value for metadata "Link".  In order to use this metadata, either qualify it by specifying %(_GeneratedXbfFiles.Link), or ensure that all items in this list define a value for this metadata. [C:\h\w\A2410948\t\dotnetSdkTests\wlal550e.tx3\ItSetsCorrect---81D5B905\UwpXbfLinkTest\UwpXbfLinkTest.csproj]
[xUnit.net 00:01:08.51]       StdErr:
[xUnit.net 00:01:08.51]       
[xUnit.net 00:01:08.51]       , but found 1 (difference of 1).

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot test ItSetsCorrectLinkMetadataOnGeneratedXbfFilesWhenUsingArtifactsOutput is failing because of this change. Please fix:

[xUnit.net 00:01:08.51]       C:\h\w\A2410948\p\d\sdk\11.0.100-...

Fixed in the latest commit. The MSB4096 was caused by using unqualified %(Link) and %(FullPath) in the Update condition — MSBuild requires all items to define metadata when using unqualified batching, and our injected items (like those from MarkupCompilePass2) don't have Link pre-defined. Changed to the qualified forms %(_GeneratedXbfFiles.Link) and %(_GeneratedXbfFiles.FullPath), which return empty string safely for items without those metadata values.

@github-actions

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Jul 27, 2026
@dfederm

dfederm commented Jul 27, 2026

Copy link
Copy Markdown

@marcpopMSFT ?

@github-actions github-actions Bot removed the stale label Jul 27, 2026
Copilot AI and others added 4 commits July 29, 2026 16:28
…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>
…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>
… condition

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
@marcpopMSFT
marcpopMSFT force-pushed the copilot/fix-xbf-subdirectory-paths branch from 7f73d14 to a3b40cb Compare July 29, 2026 23:28
@marcpopMSFT
marcpopMSFT requested a review from a team as a code owner July 29, 2026 23:28
@marcpopMSFT
marcpopMSFT enabled auto-merge (squash) July 29, 2026 23:39
@marcpopMSFT
marcpopMSFT requested a review from baronfel July 29, 2026 23:39
@marcpopMSFT

Copy link
Copy Markdown
Member

@dfederm sorry, hadn't had time to review or test the change. Looks reasonable. Now needs new signoff because i had to remerge so I re-requested from @baronfel Will merge once we have that.

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree with Marc - this looks solid.

…f xUnit [WindowsOnlyFact]

The test project uses MSTest, not xUnit. Replace the non-existent
WindowsOnlyFactAttribute with the correct MSTest equivalent that
all other Windows-only tests in this file use.

Fixes CS0246 build error in CI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 65d4a706-84ae-4b55-82d0-d700601b113f
@marcpopMSFT
marcpopMSFT merged commit f688063 into main Jul 30, 2026
21 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/fix-xbf-subdirectory-paths branch July 30, 2026 01:26
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 31, 2026
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

5 participants