Skip to content

[msbuild] Optimize PNG, property list and localization bundle resources for all platforms. Fixes #20129 - #26260

Open
rolfbjarne wants to merge 7 commits into
mainfrom
dev/rolf/dev-rolf-add-optimization-targets-to-net
Open

[msbuild] Optimize PNG, property list and localization bundle resources for all platforms. Fixes #20129#26260
rolfbjarne wants to merge 7 commits into
mainfrom
dev/rolf/dev-rolf-add-optimization-targets-to-net

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

This enables resource optimization (previously effectively iOS-only) for all Apple platforms and modernizes the implementation:

  • PNG images are optimized with pngcrush (with -rem text on iOS/tvOS/Mac Catalyst to match Xcode, omitted on macOS).
  • Property lists (.plist) are converted to binary using the managed PObject type instead of shelling out to plutil. This makes the task faster (no external process) and lets it run on Windows without remoting.
  • Localization files (.strings) are converted to binary plists using a new OptimizeLocalization task (they still need plutil since PObject doesn't parse OpenStep .strings syntax).
  • OptimizePNGs and OptimizePropertyLists now default to true for release builds on iOS, tvOS and Mac Catalyst in .NET 11+ (opt-in before then, and off for debug/macOS builds).
  • Resources embedded in their original form from referenced libraries now honor the consuming app's optimization settings (via a new IsOriginalResource metadata).
  • The _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/OptimizePropertyLists has been updated accordingly.

Fixes #20129

🤖 Pull request created by Copilot

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
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 _OptimizeLocalizationFiles into 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 text behavior by platform; plist optimization moves to managed PObject; .strings optimization uses a new OptimizeLocalization task.
  • Add/extend tests and update documentation for OptimizePNGs and OptimizePropertyLists default 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.

Comment thread msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs
Comment thread msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeLocalization.cs Outdated
@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne marked this pull request as ready for review July 27, 2026 18:11
@rolfbjarne
rolfbjarne requested a review from mauroa as a code owner July 27, 2026 18:11
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits July 28, 2026 18:48
…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
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits July 29, 2026 20:18
* 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
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 8bfcfef31817620cbf3b464b34e9f699a947f11c [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [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
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 8bfcfef31817620cbf3b464b34e9f699a947f11c [PR build]

@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optimization targets to .NET

4 participants