Skip to content

Commit

Permalink
Remove the 'Resources' prefix from BundleResource
Browse files Browse the repository at this point in the history
Fixes #23554

Prior to Maui 8.0.70, there was a bug that only removed the "Resources/" prefix, and not the correct "Platforms/iOS/Resource": #16734

This PR #23269 fixes the original issue, but now exposed the case where BundleResource were included in the root Resources folder instead of the Platforms/iOS/ folder.
  • Loading branch information
mattleibow authored and github-actions committed Aug 5, 2024
1 parent 911f058 commit 5ace711
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,63 @@

</Target>

<!--
Workaround for the issue where the resource starts with the Resources/ prefix,
either in the Identity or Link metadata. The fix is to assume that was not intended
since that is how it worked in 8.0.60 and earlier.
However, if there is a LogicalName metadata, we will skip processing as that is what
was explicitly set (even though the build will fail).
-->
<PropertyGroup>
<CollectBundleResourcesDependsOn>
_MauiRemoveResourcesPrefixFromBundleResource;
$(CollectBundleResourcesDependsOn);
</CollectBundleResourcesDependsOn>
</PropertyGroup>
<Target Name="_MauiRemoveResourcesPrefixFromBundleResource">
<!-- Collect the items into 2 categories: Link or no Link -->
<ItemGroup>
<_MauiBundleResourceWithLogicalName
Include="@(BundleResource->HasMetadata('LogicalName'))" />
<_MauiBundleResourceWithLink
Include="@(BundleResource->HasMetadata('Link'))"
Exclude="@(_MauiBundleResourceWithLogicalName)" />
<_MauiBundleResourceWithoutLink
Include="@(BundleResource)"
Exclude="@(_MauiBundleResourceWithLink);@(_MauiBundleResourceWithLogicalName)" />
</ItemGroup>
<!-- Set the LogicalName to be a path relative to Resources -->
<ItemGroup>
<_MauiBundleResourceWithRelativeLogicalName
Include="@(_MauiBundleResourceWithLink)"
LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '$(MSBuildProjectDirectory)/%(Link)'))" />
<_MauiBundleResourceWithRelativeLogicalName
Include="@(_MauiBundleResourceWithoutLink)"
LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '%(FullPath)'))" />
</ItemGroup>
<!-- Remove all items that are not below the Resources directory -->
<ItemGroup>
<_MauiBundleResourceWithCorrectLogicalName
Include="@(_MauiBundleResourceWithRelativeLogicalName)"
Condition="!$([System.String]::new('%(_MauiBundleResourceWithRelativeLogicalName.LogicalName)').StartsWith('..'))" />
</ItemGroup>
<!-- Replace the items in @(BundleResource) with the ones with a correct LogicalName -->
<ItemGroup>
<BundleResource Remove="@(_MauiBundleResourceWithCorrectLogicalName)" />
<BundleResource Include="@(_MauiBundleResourceWithCorrectLogicalName)" />
</ItemGroup>
<!-- Clean up items -->
<ItemGroup>
<_MauiBundleResourceResult Include="@(BundleResource)" />
<_MauiBundleResourceWithLogicalName Remove="@(_MauiBundleResourceWithLogicalName)" />
<_MauiBundleResourceWithLink Remove="@(_MauiBundleResourceWithLink)" />
<_MauiBundleResourceWithoutLink Remove="@(_MauiBundleResourceWithoutLink)" />
<_MauiBundleResourceWithRelativeLogicalName Remove="@(_MauiBundleResourceWithRelativeLogicalName)" />
<_MauiBundleResourceWithCorrectLogicalName Remove="@(_MauiBundleResourceWithCorrectLogicalName)" />
<_MauiBundleResourceResult Remove="@(_MauiBundleResourceResult)" />
</ItemGroup>
</Target>

<!-- Import Maui Single Project property pages -->
<PropertyGroup Condition="'$(MauiDesignTimeTargetsPath)' == ''">
<MauiDesignTimeTargetsPath>$(MSBuildExtensionsPath)\Microsoft\VisualStudio\Maui\Maui.DesignTime.targets</MauiDesignTimeTargetsPath>
Expand Down

0 comments on commit 5ace711

Please sign in to comment.