-
Notifications
You must be signed in to change notification settings - Fork 2k
Support finding nearest TFM to collect assets from #18068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b3b5062
Support finding nearest TFM to collect assets from
mattleibow 3deb6fa
Update Microsoft.Maui.Resizetizer.After.targets
mattleibow 28eb17a
Update Microsoft.Maui.Resizetizer.After.targets
mattleibow e010bd7
Update Microsoft.Maui.Resizetizer.After.targets
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/TestUtils/src/Microsoft.Maui.IntegrationTests/ResizetizerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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."); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
OriginalProjectReferenceItemSpecorNearestTargetFrameworkare blank? It seems like we should handle that case.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
_ResolvedProjectReferencePathsitem group is the result of theResolveProjectReferencestarget.There was a problem hiding this comment.
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.