Skip to content

Commit

Permalink
[release/9.0.1xx-preview7] Remove the 'Resources' prefix from BundleR…
Browse files Browse the repository at this point in the history
…esource (#24024)

* Remove the 'Resources' prefix from BundleResource

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.

* Update Microsoft.Maui.Controls.SingleProject.targets

* Update Microsoft.Maui.Controls.SingleProject.targets

* Add a test

* string

---------

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
  • Loading branch information
github-actions[bot] and mattleibow committed Aug 6, 2024
1 parent 4c287d0 commit 9272311
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@

</Target>

<!--
TEMPORARY 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.
See: https://github.com/xamarin/xamarin-macios/issues/20968
-->
<Target Name="_MauiBefore_CollectBundleResources" BeforeTargets="_CollectBundleResources">
<PropertyGroup>
<_MauiOld_ResourcePrefix>$(_ResourcePrefix)</_MauiOld_ResourcePrefix>
<_ResourcePrefix>Resources;$(_ResourcePrefix)</_ResourcePrefix>
</PropertyGroup>
</Target>
<Target Name="_MauiAfter_CollectBundleResources" AfterTargets="_CollectBundleResources">
<PropertyGroup>
<_ResourcePrefix>$(_MauiOld_ResourcePrefix)</_ResourcePrefix>
</PropertyGroup>
</Target>

<!-- Import Maui Single Project property pages -->
<PropertyGroup Condition="'$(MauiDesignTimeTargetsPath)' == ''">
<MauiDesignTimeTargetsPath>$(MSBuildExtensionsPath)\Microsoft\VisualStudio\Maui\Maui.DesignTime.targets</MauiDesignTimeTargetsPath>
Expand Down
31 changes: 31 additions & 0 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,37 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

[Test]
[TestCase("maui", "ios")]
[TestCase("maui", "maccatalyst")]
[TestCase("maui-blazor", "ios")]
[TestCase("maui-blazor", "maccatalyst")]
public void BuildWithCustomBundleResource(string id, string framework)
{
var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");

Assert.IsTrue(DotnetInternal.New(id, projectDir, DotNetCurrent),
$"Unable to create template {id}. Check test output for errors.");

File.WriteAllText(Path.Combine(projectDir, "Resources", "testfile.txt"), "Something here :)");

FileUtilities.ReplaceInFile(projectFile,
"</Project>",
$"""
<ItemGroup>
<BundleResource Include="Resources\testfile.txt" />
</ItemGroup>
</Project>
""");

var extendedBuildProps = BuildProps;
extendedBuildProps.Add($"TargetFramework={DotNetCurrent}-{framework}");

Assert.IsTrue(DotnetInternal.Build(projectFile, "Debug", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

[Test]
[TestCase("maui", $"{DotNetCurrent}-ios", "ios-arm64")]
[TestCase("maui", $"{DotNetCurrent}-ios", "iossimulator-arm64")]
Expand Down

0 comments on commit 9272311

Please sign in to comment.