diff --git a/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets b/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets index 2d7954d81318..a08c3307e19c 100644 --- a/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets +++ b/src/SingleProject/Resizetizer/src/nuget/buildTransitive/Microsoft.Maui.Resizetizer.After.targets @@ -256,25 +256,35 @@ + ItemName="_ImportedMauiItem" /> - - - + + + + <_ResizetizeCollectItemsProjectWithOIS Include="@(_ResolvedProjectReferencePaths->HasMetadata('OriginalProjectReferenceItemSpec'))" /> + + <_ResizetizeCollectItemsProjectWithItemSpec Include="@(_ResizetizeCollectItemsProjectWithOIS->'%(OriginalProjectReferenceItemSpec)')" /> + + <_ResizetizeCollectItemsProject Include="@(_ResizetizeCollectItemsProjectWithItemSpec->HasMetadata('NearestTargetFramework'))" /> + + <_ResizetizeCollectItemsProject Include="@(ProjectReference)" Exclude="@(_ResizetizeCollectItemsProject)" NearestTargetFramework="$(TargetFramework)" /> + + ItemName="_ImportedMauiItem" /> + diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/ResizetizerTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/ResizetizerTests.cs new file mode 100644 index 000000000000..e2d8e9a9f183 --- /dev/null +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/ResizetizerTests.cs @@ -0,0 +1,96 @@ +using Microsoft.Maui.IntegrationTests.Apple; + +namespace Microsoft.Maui.IntegrationTests; + +public class ResizetizerTests : BaseBuildTest +{ + const string BlankSvgContents = + """ + + + + + """; + + [Test] + // windows unpackaged/exe + [TestCase("maui", "classlib", true)] // net8.0 + [TestCase("maui", "mauilib", true)] // net8.0-xxx + [TestCase("maui-blazor", "classlib", true)] // net8.0 + [TestCase("maui-blazor", "mauilib", true)] // net8.0-xxx + // windows packaged/msix + [TestCase("maui", "classlib", false)] // net8.0 + [TestCase("maui", "mauilib", false)] // net8.0-xxx + [TestCase("maui-blazor", "classlib", false)] // net8.0 + [TestCase("maui-blazor", "mauilib", false)] // net8.0-xxx + public void CollectsAssets(string id, string libid, bool unpackaged) + { + // new app + var appDir = Path.Combine(TestDirectory, "theapp"); + var appFile = Path.Combine(appDir, $"{Path.GetFileName(appDir)}.csproj"); + Assert.IsTrue(DotnetInternal.New(id, appDir, DotNetCurrent), + $"Unable to create template {id}. Check test output for errors."); + + // new lib + var libDir = Path.Combine(TestDirectory, "thelib"); + var libFile = Path.Combine(libDir, $"{Path.GetFileName(libDir)}.csproj"); + Assert.IsTrue(DotnetInternal.New(libid, libDir, DotNetCurrent), + $"Unable to create template {libid}. Check test output for errors."); + + // add a project reference + FileUtilities.ReplaceInFile(appFile, + "", + """ + + + + + """); + + // toggle packaged / unpackaged + if (unpackaged) + { + FileUtilities.ReplaceInFile(appFile, + "", + """ + + None + + + """); + + } + + // add the svg file + File.WriteAllText(Path.Combine(libDir, "the_image.svg"), BlankSvgContents); + + // add the + FileUtilities.ReplaceInFile(libFile, + "", + """ + + true + true + + + + + + """); + + // build + Assert.IsTrue(DotnetInternal.Build(appFile, "Debug", properties: BuildProps), + $"Project {Path.GetFileName(appFile)} failed to build. Check test output/attachments for errors."); + + // assert + Assert.True(File.Exists(Path.Combine(appDir, $"obj\\Debug\\{DotNetCurrent}-android\\resizetizer\\r\\drawable-mdpi\\the_image.png")), + "Android was missing the image file."); + Assert.True(File.Exists(Path.Combine(appDir, $"obj\\Debug\\{DotNetCurrent}-ios\\iossimulator-x64\\resizetizer\\r\\the_image.png")), + "iOS was missing the image file."); + Assert.True(File.Exists(Path.Combine(appDir, $"obj\\Debug\\{DotNetCurrent}-maccatalyst\\maccatalyst-x64\\resizetizer\\r\\the_image.png")), + "Mac Catalyst was missing the image file."); + if (TestEnvironment.IsWindows) + Assert.True(File.Exists(Path.Combine(appDir, $"obj\\Debug\\{DotNetCurrent}-windows10.0.19041.0\\win10-x64\\resizetizer\\r\\the_image.scale-100.png")), + "Windows was missing the image file."); + } +}