Skip to content

[msbuild] Restore library resources on incremental builds Fixes #5755#26004

Merged
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/issue-5755-library-xcassets-incremental
Jul 14, 2026
Merged

[msbuild] Restore library resources on incremental builds Fixes #5755#26004
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/issue-5755-library-xcassets-incremental

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Image assets (and other compiled resources) coming from referenced
libraries were lost on incremental builds.

When a library is referenced, its embedded resources are extracted by the
_UnpackLibraryResources target into typed item groups (ImageAsset,
AtlasTexture, InterfaceDefinition, Collada, CoreMLModel,
SceneKitAsset). That target is incremental (keyed on the referenced
assemblies), so on a rebuild where the library is unchanged it's skipped
and those item groups end up empty.

For most resource types this is harmless because the resulting files are
copied individually and persist in the app bundle. But image assets from
all projects are compiled together into a single Assets.car by actool.
When an app-owned asset changes, actool re-runs and regenerates
Assets.car from the (now empty of library assets) ImageAsset group,
dropping every image asset that came from a referenced library.

Fix this the same way the partial app manifests are already handled: route
the unpacked typed resources to private item groups, cache them to disk,
and restore them into the real item groups from a new always-run
_LoadUnpackedLibraryResources target, so they're present even when
_UnpackLibraryResources is skipped.

Also add a regression test that builds an app referencing a library with
image assets, touches an app-owned asset to force actool to re-run, and
verifies the library's asset is still present in Assets.car.

Fixes #5755

🤖 Pull request created by Copilot

Image assets (and other compiled resources) coming from referenced
libraries were lost on incremental builds.

When a library is referenced, its embedded resources are extracted by the
`_UnpackLibraryResources` target into typed item groups (`ImageAsset`,
`AtlasTexture`, `InterfaceDefinition`, `Collada`, `CoreMLModel`,
`SceneKitAsset`). That target is incremental (keyed on the referenced
assemblies), so on a rebuild where the library is unchanged it's skipped
and those item groups end up empty.

For most resource types this is harmless because the resulting files are
copied individually and persist in the app bundle. But image assets from
all projects are compiled together into a single `Assets.car` by `actool`.
When an app-owned asset changes, `actool` re-runs and regenerates
`Assets.car` from the (now empty of library assets) `ImageAsset` group,
dropping every image asset that came from a referenced library.

Fix this the same way the partial app manifests are already handled: route
the unpacked typed resources to private item groups, cache them to disk,
and restore them into the real item groups from a new always-run
`_LoadUnpackedLibraryResources` target, so they're present even when
`_UnpackLibraryResources` is skipped.

Also add a regression test that builds an app referencing a library with
image assets, touches an app-owned asset to force `actool` to re-run, and
verifies the library's asset is still present in `Assets.car`.

Fixes #5755

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne marked this pull request as ready for review July 9, 2026 17:42
@rolfbjarne rolfbjarne requested a review from mauroa as a code owner July 9, 2026 17:42
Copilot AI review requested due to automatic review settings July 9, 2026 17:42

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

Fixes an MSBuild incremental-build issue where typed resources (notably ImageAsset inputs to actool) unpacked from referenced libraries could disappear from the item graph when _UnpackLibraryResources is skipped, causing Assets.car to be regenerated without library assets (#5755).

Changes:

  • Cache typed resources produced by _UnpackLibraryResources to disk and restore them via a new always-run _LoadUnpackedLibraryResources target before asset compilation.
  • Add a regression test that builds an app referencing a library with .xcassets, forces actool to re-run by touching an app asset, and asserts the library image asset remains in Assets.car.
  • Add app-owned .xcassets to the test app project to ensure actool runs for the app itself.

Reviewed changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/dotnet/UnitTests/AssetsTest.cs Adds a regression test that verifies referenced-library image assets survive incremental rebuilds that re-run actool.
tests/dotnet/AppWithLibraryWithResourcesReference/shared.csproj Includes an app-owned ImageAsset item so actool runs and can reproduce the incremental-loss scenario.
tests/dotnet/AppWithLibraryWithResourcesReference/AppImages.xcassets/Contents.json Adds the root asset catalog metadata for the test app’s image assets.
tests/dotnet/AppWithLibraryWithResourcesReference/AppImages.xcassets/AppImage.imageset/Contents.json Adds the imageset metadata for the app-owned AppImage asset used in the regression test.
msbuild/Xamarin.Shared/Xamarin.Shared.targets Routes unpacked typed resources to private item groups, writes them to cache files, and restores them via _LoadUnpackedLibraryResources during incremental builds.

Comment thread msbuild/Xamarin.Shared/Xamarin.Shared.targets
Address PR review feedback: _LoadUnpackedLibraryResources restored cached
typed resources whenever the cache files existed, even for a library that
was removed since the last full unpack. When several libraries are
referenced and only one is removed, _UnpackLibraryResources is skipped
(the remaining references are unchanged), so the combined cache would keep
re-adding the removed library's resources - and its image assets would get
compiled into Assets.car again.

Read each cache into a private _CachedUnpacked* group and only restore
items whose 'BundledInAssembly' is still among the current
@(_UnpackLibraryResourceItems), mirroring the existing per-library
_BundleResourceWithLogicalName restore behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7e4e7bdd-8fa5-46c8-8649-9e84e6129329
@vs-mobiletools-engineering-service2

This comment has been minimized.

@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: 811c9e2b56da9240742b8c27e42caef0180650b0 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #811c9e2] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 199 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 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 17 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 18 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: 811c9e2b56da9240742b8c27e42caef0180650b0 [PR build]

@rolfbjarne rolfbjarne enabled auto-merge (squash) July 14, 2026 06:14
@rolfbjarne rolfbjarne merged commit cbe5316 into main Jul 14, 2026
56 checks passed
@rolfbjarne rolfbjarne deleted the dev/rolf/issue-5755-library-xcassets-incremental branch July 14, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loosing icons and images when using xcassets in libraries

5 participants