Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,35 @@
<CallTarget Targets="GetMauiItems" Condition="'$(ResizetizerIncludeSelfProject)' == 'True'">
<Output
TaskParameter="TargetOutputs"
ItemName="ImportedMauiItem" />
ItemName="_ImportedMauiItem" />
</CallTarget>

<!-- Invoke the GetMauiItems target on all project references -->
<!-- This will accumulate images into our MauiImage group -->
<!--<MSBuild Targets="GetMauiItems" Projects="@(_MSBuildProjectReferenceExistent)">-->
<!-- Invoke the GetMauiItems target on all project references. This will accumulate images into our MauiImage group -->
<ItemGroup>
<!-- Filter out the items missing the OriginalProjectReferenceItemSpec because this is essential -->
<_ResizetizeCollectItemsProjectWithOIS Include="@(_ResolvedProjectReferencePaths->HasMetadata('OriginalProjectReferenceItemSpec'))" />
<!-- Convert the Identity from the final assembly path to the ProjectReference -->
<_ResizetizeCollectItemsProjectWithItemSpec Include="@(_ResizetizeCollectItemsProjectWithOIS->'%(OriginalProjectReferenceItemSpec)')" />
<!-- Add the resolved references if and only if they have NearestTargetFramework defined -->
<_ResizetizeCollectItemsProject Include="@(_ResizetizeCollectItemsProjectWithItemSpec->HasMetadata('NearestTargetFramework'))" />
<!-- If any resolved paths were missing OriginalProjectReferenceItemSpec or NearestTargetFramework, fall back to the
previous functionality with using the ProjectReference items and the CURRENT project's TargetFramework -->
<_ResizetizeCollectItemsProject Include="@(ProjectReference)" Exclude="@(_ResizetizeCollectItemsProject)" NearestTargetFramework="$(TargetFramework)" />
</ItemGroup>
<MSBuild
Targets="GetMauiItems"
Projects="@(ProjectReference)"
Projects="%(_ResizetizeCollectItemsProject.Identity)"
BuildInParallel="true"
Properties="TargetFramework=$(TargetFramework)"
Properties="TargetFramework=%(_ResizetizeCollectItemsProject.NearestTargetFramework)"
SkipNonexistentProjects="true"
SkipNonexistentTargets="true">
<Output
TaskParameter="TargetOutputs"
ItemName="ImportedMauiItem" />
ItemName="_ImportedMauiItem" />
</MSBuild>

<ItemGroup>
<ImportedMauiItem Include="@(_ImportedMauiItem)" />
<MauiImage
Include="@(ImportedMauiItem)"
Condition="'%(ImportedMauiItem.ItemGroupName)' == 'MauiImage'" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Microsoft.Maui.IntegrationTests.Apple;

namespace Microsoft.Maui.IntegrationTests;

public class ResizetizerTests : BaseBuildTest
{
const string BlankSvgContents =
"""
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="456" height="456" viewBox="0 0 456 456" version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="456" height="456" fill="#512BD4" />
</svg>
""";

[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,
"</Project>",
"""
<ItemGroup>
<ProjectReference Include="..\thelib\thelib.csproj" />
</ItemGroup>
</Project>
""");

// toggle packaged / unpackaged
if (unpackaged)
{
FileUtilities.ReplaceInFile(appFile,
"</Project>",
"""
<PropertyGroup>
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>
</Project>
""");

}

// add the svg file
File.WriteAllText(Path.Combine(libDir, "the_image.svg"), BlankSvgContents);

// add the <MauiImage>
FileUtilities.ReplaceInFile(libFile,
"</Project>",
"""
<PropertyGroup>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
</PropertyGroup>
<ItemGroup>
<MauiImage Include="the_image.svg" />
</ItemGroup>
</Project>
""");

// 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.");
}
}