From 73be39f4788902a6861b960573b1e27f33b3999e Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 2 Aug 2024 14:05:37 +0200 Subject: [PATCH 1/5] 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": https://github.com/dotnet/maui/issues/16734 This PR https://github.com/dotnet/maui/pull/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. --- ...rosoft.Maui.Controls.SingleProject.targets | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets index c8183a8997d5..e0db69a5cf93 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets @@ -61,6 +61,63 @@ + + + + _MauiRemoveResourcesPrefixFromBundleResource; + $(CollectBundleResourcesDependsOn); + + + + + + <_MauiBundleResourceWithLogicalName + Include="@(BundleResource->HasMetadata('LogicalName'))" /> + <_MauiBundleResourceWithLink + Include="@(BundleResource->HasMetadata('Link'))" + Exclude="@(_MauiBundleResourceWithLogicalName)" /> + <_MauiBundleResourceWithoutLink + Include="@(BundleResource)" + Exclude="@(_MauiBundleResourceWithLink);@(_MauiBundleResourceWithLogicalName)" /> + + + + <_MauiBundleResourceWithRelativeLogicalName + Include="@(_MauiBundleResourceWithLink)" + LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '$(MSBuildProjectDirectory)/%(Link)'))" /> + <_MauiBundleResourceWithRelativeLogicalName + Include="@(_MauiBundleResourceWithoutLink)" + LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '%(FullPath)'))" /> + + + + <_MauiBundleResourceWithCorrectLogicalName + Include="@(_MauiBundleResourceWithRelativeLogicalName)" + Condition="!$([System.String]::new('%(_MauiBundleResourceWithRelativeLogicalName.LogicalName)').StartsWith('..'))" /> + + + + + + + + + <_MauiBundleResourceResult Include="@(BundleResource)" /> + <_MauiBundleResourceWithLogicalName Remove="@(_MauiBundleResourceWithLogicalName)" /> + <_MauiBundleResourceWithLink Remove="@(_MauiBundleResourceWithLink)" /> + <_MauiBundleResourceWithoutLink Remove="@(_MauiBundleResourceWithoutLink)" /> + <_MauiBundleResourceWithRelativeLogicalName Remove="@(_MauiBundleResourceWithRelativeLogicalName)" /> + <_MauiBundleResourceWithCorrectLogicalName Remove="@(_MauiBundleResourceWithCorrectLogicalName)" /> + <_MauiBundleResourceResult Remove="@(_MauiBundleResourceResult)" /> + + + $(MSBuildExtensionsPath)\Microsoft\VisualStudio\Maui\Maui.DesignTime.targets From f089081fd9f6d1596bf293aacb784cddb797aa26 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 2 Aug 2024 15:51:57 +0200 Subject: [PATCH 2/5] Update Microsoft.Maui.Controls.SingleProject.targets --- .../Microsoft.Maui.Controls.SingleProject.targets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets index e0db69a5cf93..a387759ab01c 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets @@ -69,7 +69,7 @@ was explicitly set (even though the build will fail). --> - + _MauiRemoveResourcesPrefixFromBundleResource; $(CollectBundleResourcesDependsOn); @@ -90,9 +90,11 @@ <_MauiBundleResourceWithRelativeLogicalName Include="@(_MauiBundleResourceWithLink)" + Condition="@(_MauiBundleResourceWithLink->Count()) > 0" LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '$(MSBuildProjectDirectory)/%(Link)'))" /> <_MauiBundleResourceWithRelativeLogicalName Include="@(_MauiBundleResourceWithoutLink)" + Condition="@(_MauiBundleResourceWithoutLink->Count()) > 0" LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '%(FullPath)'))" /> From 7e95ccea87b6dbea3c44b3aa9b3f45ad89775b96 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 5 Aug 2024 14:52:01 +0200 Subject: [PATCH 3/5] Update Microsoft.Maui.Controls.SingleProject.targets --- ...rosoft.Maui.Controls.SingleProject.targets | 65 ++++--------------- 1 file changed, 12 insertions(+), 53 deletions(-) diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets index a387759ab01c..6f4069e6d36d 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets @@ -62,62 +62,21 @@ - - - _MauiRemoveResourcesPrefixFromBundleResource; - $(CollectBundleResourcesDependsOn); - - - - - - <_MauiBundleResourceWithLogicalName - Include="@(BundleResource->HasMetadata('LogicalName'))" /> - <_MauiBundleResourceWithLink - Include="@(BundleResource->HasMetadata('Link'))" - Exclude="@(_MauiBundleResourceWithLogicalName)" /> - <_MauiBundleResourceWithoutLink - Include="@(BundleResource)" - Exclude="@(_MauiBundleResourceWithLink);@(_MauiBundleResourceWithLogicalName)" /> - - - - <_MauiBundleResourceWithRelativeLogicalName - Include="@(_MauiBundleResourceWithLink)" - Condition="@(_MauiBundleResourceWithLink->Count()) > 0" - LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '$(MSBuildProjectDirectory)/%(Link)'))" /> - <_MauiBundleResourceWithRelativeLogicalName - Include="@(_MauiBundleResourceWithoutLink)" - Condition="@(_MauiBundleResourceWithoutLink->Count()) > 0" - LogicalName="$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)/Resources/', '%(FullPath)'))" /> - - - - <_MauiBundleResourceWithCorrectLogicalName - Include="@(_MauiBundleResourceWithRelativeLogicalName)" - Condition="!$([System.String]::new('%(_MauiBundleResourceWithRelativeLogicalName.LogicalName)').StartsWith('..'))" /> - - - - - - - - - <_MauiBundleResourceResult Include="@(BundleResource)" /> - <_MauiBundleResourceWithLogicalName Remove="@(_MauiBundleResourceWithLogicalName)" /> - <_MauiBundleResourceWithLink Remove="@(_MauiBundleResourceWithLink)" /> - <_MauiBundleResourceWithoutLink Remove="@(_MauiBundleResourceWithoutLink)" /> - <_MauiBundleResourceWithRelativeLogicalName Remove="@(_MauiBundleResourceWithRelativeLogicalName)" /> - <_MauiBundleResourceWithCorrectLogicalName Remove="@(_MauiBundleResourceWithCorrectLogicalName)" /> - <_MauiBundleResourceResult Remove="@(_MauiBundleResourceResult)" /> - + + + <_MauiOld_ResourcePrefix>$(_ResourcePrefix) + <_ResourcePrefix>Resources;$(_ResourcePrefix) + + + + + <_ResourcePrefix>$(_MauiOld_ResourcePrefix) + From 81f64bdf982ee5fc19982ecc4aaf01a0563a2e33 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 5 Aug 2024 23:40:04 +0800 Subject: [PATCH 4/5] Add a test --- .../TemplateTests.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs index 178eaa01bdb1..11ed4a522a83 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs @@ -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, bool 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, + "", + $""" + + + + + """); + + 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")] From c66e155c5f812a755af0e69f1ce2024baeebd008 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 6 Aug 2024 01:27:52 +0800 Subject: [PATCH 5/5] string --- .../src/Microsoft.Maui.IntegrationTests/TemplateTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs index 11ed4a522a83..6e50454f3948 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs @@ -347,7 +347,7 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType [TestCase("maui", "maccatalyst")] [TestCase("maui-blazor", "ios")] [TestCase("maui-blazor", "maccatalyst")] - public void BuildWithCustomBundleResource(string id, bool framework) + public void BuildWithCustomBundleResource(string id, string framework) { var projectDir = TestDirectory; var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");