Skip to content

[msbuild] Add validation for conflicting resources. Fixes #19029. #22996

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 4 commits into from
Jun 19, 2025

Conversation

rolfbjarne
Copy link
Member

Add validation for conflicting resources, showing a warning if the same
resource is found from multiple sources.

Fixes #19029.

@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.

@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.

@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.

@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.

@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.

@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.

@rolfbjarne rolfbjarne force-pushed the dev/rolf/msbuild-warn-if-duplicate-bundle-resources branch from 7360f12 to 777706c Compare June 5, 2025 07:20
@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.

@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.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne force-pushed the dev/rolf/msbuild-warn-if-duplicate-bundle-resources branch from 777706c to e824020 Compare June 5, 2025 10:09
@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.

@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.

@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.

@rolfbjarne rolfbjarne marked this pull request as ready for review June 16, 2025 17:23
@rolfbjarne rolfbjarne requested review from emaf and mauroa as code owners June 16, 2025 17:23
Copy link
Member

@mandel-macaque mandel-macaque left a comment

Choose a reason for hiding this comment

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

Approving since I'm not going to block for the use of Count, I trust your call in that regard.

// More than one item per LogicalName is not good at all.
var notBundledInAssembly = group.Where (item => string.IsNullOrEmpty (item.GetMetadata ("BundledInAssembly")));
var bundledInAssembly = group.Where (item => !string.IsNullOrEmpty (item.GetMetadata ("BundledInAssembly")));
if (notBundledInAssembly.Count () == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

You are using Count several times in the IEnumerable, that means that the notBundledInAssembly is being iterated several times. Why not do a ToArray and then use Length? Otherwise in the worst case scenario we are iterating over the collection 3 times.

@rolfbjarne rolfbjarne requested a review from Copilot June 18, 2025 15:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements enhanced duplicate resource detection by adding new validation logic and warnings when conflicting resources are encountered. Key changes include:

  • Updating MSBuild tasks (e.g. TextureAtlas, IBTool, ScnTool, CoreMLCompiler, CompileSceneKitAssets, ACTool, and CollectBundleResources) to compute logical names and detect duplicates.
  • Enhancing project configurations and test setups for different platforms (macOS, iOS, MacCatalyst) to incorporate the new validation.
  • Adding new methods and error/warning messages in common utilities and localization resource files.

Reviewed Changes

Copilot reviewed 20 out of 89 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/dotnet/AppWithDuplicatedResources/shared.csproj Added resource item groups with duplicate resource conditions.
tests/dotnet/AppWithDuplicatedResources/macOS/.csproj, iOS/.csproj, MacCatalyst/*.csproj Updated project files to import shared settings.
tests/common/DotNet.cs Updated AssertBuild signature with an extra ‘target’ parameter.
tests/common/Configuration.cs Introduced GetAllRuntimeIdentifiers for runtime identifier aggregation.
msbuild/Xamarin.Shared/Xamarin.Shared.targets Removed an obsolete TODO comment regarding duplicate items.
msbuild/Xamarin.MacDev.Tasks/Tasks/* Modified various tasks to incorporate duplicate resource detection and proper logical naming.
msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx Added new error and warning messages related to resource duplicate conflicts.
Comments suppressed due to low confidence (1)

tests/common/DotNet.cs:66

  • Consider updating the method documentation for 'AssertBuild' to describe the new 'target' parameter and its intended usage.
		public static ExecutionResult AssertBuild (string project, Dictionary<string, string>? properties = null, string? target = null, TimeSpan? timeout = null)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #120071c] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #120071c] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

✅ API diff vs stable

.NET ( No breaking changes )

ℹ️ Generator diff

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

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #120071c] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #120071c] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #120071c] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #120071c] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #120071c] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #120071c] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 115 tests passed 🎉

Tests counts

✅ 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: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 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

Pipeline on Agent
Hash: 120071cf20a465894d99dc63b32f862807cbad93 [PR build]

@rolfbjarne rolfbjarne merged commit a0e276b into main Jun 19, 2025
44 checks passed
@rolfbjarne rolfbjarne deleted the dev/rolf/msbuild-warn-if-duplicate-bundle-resources branch June 19, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if the build encounters multiple identically named assets
5 participants