[msbuild] Optimize PNG, property list and localization bundle resources for all platforms. Fixes #20129 - #26260
Conversation
Wire the existing PNG, property list, and localization optimizers into app and library resource pipelines, and preserve app-controlled optimization for original library resources. Fix the pngcrush invocation and add regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 80276818-6356-4fda-b04e-99842c89b86b
Match current Xcode PNG processing, improve optimizer incrementality, and use managed property list conversion where possible. Enable optimization by default for non-macOS .NET 11 release builds and update coverage and documentation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 80276818-6356-4fda-b04e-99842c89b86b
Remove remoting from the managed property list optimizer and isolate the plutil-based localization path in its own remote-capable task. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 80276818-6356-4fda-b04e-99842c89b86b
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Enables and modernizes MSBuild resource optimization across Apple platforms (not just iOS), including PNG optimization, binary plist conversion, and localization .strings compilation, with updated defaults/tests/docs.
Changes:
- Wire
_OptimizePngImages,_OptimizePropertyLists, and_OptimizeLocalizationFilesinto the .NET build flow (including incremental build coverage) and ensure original resources from referenced libraries respect the consuming app’s optimization settings. - Modernize optimization implementation: PNG optimization adds optional
-rem textbehavior by platform; plist optimization moves to managedPObject;.stringsoptimization uses a newOptimizeLocalizationtask. - Add/extend tests and update documentation for
OptimizePNGsandOptimizePropertyListsdefault behavior and semantics.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/UnpackLibraryResourcesTests.cs | Adds test coverage ensuring unpacked original BundleResources are marked for downstream processing. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/OptimizePropertyListTests.cs | New unit test validating XML plist conversion to binary plist output. |
| tests/dotnet/UnitTests/ProjectTest.cs | Enables optimization properties in relevant builds and asserts optimization targets run + incremental behavior (Catalyst). |
| tests/dotnet/MyCatalystApp/Resources/settings.plist | Adds an input plist resource to validate optimization end-to-end. |
| tests/dotnet/MyCatalystApp/Resources/en.lproj/Localizable.strings | Adds a localization input to validate .strings compilation to binary plist. |
| tests/dotnet/LibraryWithResources/shared.csproj | Adds a linked PNG resource to verify consuming-app optimization applies to referenced-library resources. |
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Wires optimization targets into the bundle resource pipeline; modernizes item handling and adds StripPngText control. |
| msbuild/Xamarin.Shared/Xamarin.Shared.props | Updates defaults for OptimizePNGs/OptimizePropertyLists (release, .NET 11+, non-macOS). |
| msbuild/Xamarin.MacDev.Tasks/Tasks/UnpackLibraryResources.cs | Marks original embedded BundleResources with IsOriginalResource metadata. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs | Switches plist optimization to managed PObject conversion. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeLocalization.cs | Introduces new task to compile .strings to binary plist via plutil. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeImage.cs | Adds platform-controlled stripping of PNG text chunks and updates argument generation. |
| docs/building-apps/build-properties.md | Updates documentation for optimization properties, defaults, and metadata override behavior. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…-optimization-targets-to-net
…ed resources The resource-optimization changes added a new 'library-image.png' BundleResource to the LibraryWithResources test project, which causes a new embedded resource in the compiled library assembly. Update the LibraryWithResources test's expected resource lists to include it, both for the item-based embedding (BundleOriginalResources=true) and the content-based embedding (BundleOriginalResources=false). This fixes the LibraryWithResources test failures on all platforms. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 52de2ba8-d456-48e7-8c3a-2a410d2b0ffa
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
* OptimizePropertyList: log an MSBuild error and return false instead of throwing when a property list can't be parsed, and only create the output directory when there's a non-empty directory component. * OptimizeLocalization: avoid null-forgiving operators and only create the output directory when there's a non-empty directory component. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 80276818-6356-4fda-b04e-99842c89b86b
…-optimization-targets-to-net
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🚀 [CI Build #8bfcfef] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 203 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
This enables resource optimization (previously effectively iOS-only) for all Apple platforms and modernizes the implementation:
pngcrush(with-rem texton iOS/tvOS/Mac Catalyst to match Xcode, omitted on macOS)..plist) are converted to binary using the managedPObjecttype instead of shelling out toplutil. This makes the task faster (no external process) and lets it run on Windows without remoting..strings) are converted to binary plists using a newOptimizeLocalizationtask (they still needplutilsincePObjectdoesn't parse OpenStep.stringssyntax).OptimizePNGsandOptimizePropertyListsnow default totruefor release builds on iOS, tvOS and Mac Catalyst in .NET 11+ (opt-in before then, and off for debug/macOS builds).IsOriginalResourcemetadata)._Optimize*targets were modernized to use<ItemGroup>inside targets instead of the legacy<CreateItem/>syntax, and incremental builds are covered by tests.Documentation for
OptimizePNGs/OptimizePropertyListshas been updated accordingly.Fixes #20129
🤖 Pull request created by Copilot