Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -261,12 +261,11 @@

<!-- Invoke the GetMauiItems target on all project references -->
<!-- This will accumulate images into our MauiImage group -->
<!--<MSBuild Targets="GetMauiItems" Projects="@(_MSBuildProjectReferenceExistent)">-->
<MSBuild
Targets="GetMauiItems"
Projects="@(ProjectReference)"
Projects="%(_ResolvedProjectReferencePaths.OriginalProjectReferenceItemSpec)"
BuildInParallel="true"
Properties="TargetFramework=$(TargetFramework)"
Properties="TargetFramework=%(_ResolvedProjectReferencePaths.NearestTargetFramework)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One difference here is that % will "batch" the call running <MSBuild/> N times. Where before it would run it a single time passing in multiple projects.

Is that a problem?

@jonathanpeppers jonathanpeppers Oct 18, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other question, is what happens if OriginalProjectReferenceItemSpec or NearestTargetFramework are blank? It seems like we should handle that case.

@mattleibow mattleibow Oct 19, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first question, you just discovered a huge bug. Before, it would run all the projects with the same TFM - even if that project did not have or support it. The new way has a different TFM for each project. So I am thinking multiple builds is actually the correct way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the second question, I will first filter out the items that are missing these values to be safe, but they should always have them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if %(OriginalProjectReferenceItemSpec) is blank it should just use %(Identity) and %(NearestTargetFramework) fall back to $(TargetFramework)?

MSBuild is so loosely typed these could randomly become blank in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, Identity is the path of the dll since the _ResolvedProjectReferencePaths item group is the result of the ResolveProjectReferences target.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the things to try and look at the resolved items, and any missing ones we use the project refs. For the TFM, we first try the nearest and if that is not found then we try the current app's TFM.

SkipNonexistentProjects="true"
SkipNonexistentTargets="true">
<Output
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.");
}
}