Skip to content

Commit e5b7863

Browse files
committed
[msbuild] Fix duplicate resources when bundling original resources. (#21990)
1 parent 4c1667e commit e5b7863

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

msbuild/Xamarin.MacDev.Tasks/Tasks/PackLibraryResources.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ public override bool Execute ()
4949
{
5050
var results = new List<ITaskItem> ();
5151

52+
var hashOriginalResources = new HashSet<string> (BundleOriginalResourcesWithLogicalNames.Select (v => v.ItemSpec));
53+
5254
foreach (var item in BundleResourcesWithLogicalNames) {
55+
if (hashOriginalResources.Contains (item.ItemSpec)) {
56+
Log.LogMessage (MessageImportance.Low, $"Skipping BundleResourcesWithLogicalNames={item.ItemSpec}, because it's also specified in BundleOriginalResourcesWithLogicalNames");
57+
continue;
58+
}
59+
5360
var logicalName = item.GetMetadata ("LogicalName");
5461

5562
if (string.IsNullOrEmpty (logicalName)) {

tests/BundledResources/ResourcesTest.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using System;
1111
using System.IO;
12+
using System.Linq;
1213
using NUnit.Framework;
1314

1415
using Foundation;
@@ -41,10 +42,14 @@ public void Bundled ()
4142
if (!hasResources) {
4243
Assert.That (resources.Length, Is.EqualTo (0), "No resources");
4344
} else {
44-
Assert.That (resources.Length, Is.GreaterThanOrEqualTo (2), "Resources");
45-
Assert.That (resources, Contains.Item ("__monotouch_content_basn3p08.png"), "res-basn3p08.png");
46-
Assert.That (resources, Contains.Item ("__monotouch_content_basn3p08__with__loc.png"), "res-basn3p08_with_loc.png");
47-
Assert.That (resources, Contains.Item ("__monotouch_content_xamvideotest.mp4"), "res-xamvideotest.mp4");
45+
var expectedResources = new string [] {
46+
"basn3p08.png",
47+
"basn3p08__with__loc.png",
48+
"xamvideotest.mp4",
49+
};
50+
var oldPrefixed = expectedResources.Select (v => $"__monotouch_content_{v}").ToArray ();
51+
var newPrefixed = expectedResources.Select (v => $"__monotouch_item_BundleResource_{v}").ToArray ();
52+
Assert.That (resources, Is.EquivalentTo (oldPrefixed).Or.EquivalentTo (newPrefixed), "Resources");
4853
}
4954
}
5055
}

tests/dotnet/UnitTests/ProjectTest.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,19 @@ public void BuildBindingsTest2 (ApplePlatform platform)
232232
Assert.That (resourceBundle, Does.Exist, "Bundle existence");
233233
}
234234

235-
[TestCase ("iOS", "monotouch")]
236-
[TestCase ("tvOS", "monotouch")]
237-
[TestCase ("macOS", "xammac")]
238-
[TestCase ("MacCatalyst", "monotouch")]
239-
public void BuildBundledResources (string platform, string prefix)
235+
[TestCase ("iOS", "monotouch", true)]
236+
[TestCase ("tvOS", "monotouch", true)]
237+
[TestCase ("macOS", "xammac", true)]
238+
[TestCase ("MacCatalyst", "monotouch", true)]
239+
[TestCase ("iOS", "monotouch", false)]
240+
[TestCase ("tvOS", "monotouch", false)]
241+
[TestCase ("macOS", "xammac", false)]
242+
[TestCase ("MacCatalyst", "monotouch", false)]
243+
[TestCase ("iOS", "monotouch", null)]
244+
[TestCase ("tvOS", "monotouch", null)]
245+
[TestCase ("macOS", "xammac", null)]
246+
[TestCase ("MacCatalyst", "monotouch", null)]
247+
public void BuildBundledResources (string platform, string prefix, bool? bundleOriginalResources)
240248
{
241249
Configuration.IgnoreIfIgnoredPlatform (platform);
242250
var assemblyName = "BundledResources";
@@ -877,9 +885,6 @@ public void LibraryWithResources (ApplePlatform platform, bool? bundleOriginalRe
877885
var platformPrefix = (platform == ApplePlatform.MacOSX) ? "xammac" : "monotouch";
878886
if (actualBundleOriginalResources) {
879887
expectedResources = new string [] {
880-
$"__{platformPrefix}_content_A.ttc",
881-
$"__{platformPrefix}_content_B.otf",
882-
$"__{platformPrefix}_content_C.ttf",
883888
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0001.png",
884889
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0002.png",
885890
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0003.png",

0 commit comments

Comments
 (0)