diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 5dd66b541154..529c20b42597 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -90,6 +90,9 @@ + _CollectBundleResources; + _PackLibraryResources; + _UnpackLibraryResources; $(BuildDependsOn); _CreateAppBundle; Codesign; @@ -98,7 +101,6 @@ - _CollectBundleResources; _DetectAppManifest; _CopyResourcesToBundle; _CompileAppManifest; diff --git a/tests/BundledResources/ResourcesTest.cs b/tests/BundledResources/ResourcesTest.cs index c0a787c5f065..148a18df97d8 100644 --- a/tests/BundledResources/ResourcesTest.cs +++ b/tests/BundledResources/ResourcesTest.cs @@ -32,7 +32,12 @@ public void Bundled () // resources are removed by the linker or an extra step (e.g. "link sdk" or "don't link") but that // extra step is done only on device (to keep the simulator builds as fast as possible) var resources = typeof(ResourcesTest).Assembly.GetManifestResourceNames (); - if (Runtime.Arch == Arch.DEVICE) { +#if __MACOS__ + var hasResources = false; +#else + var hasResources = Runtime.Arch != Arch.DEVICE; +#endif + if (!hasResources) { Assert.That (resources.Length, Is.EqualTo (0), "No resources"); } else { Assert.That (resources.Length, Is.GreaterThanOrEqualTo (2), "Resources"); @@ -41,4 +46,4 @@ public void Bundled () } } } -} \ No newline at end of file +} diff --git a/tests/BundledResources/dotnet/iOS/BundledResources.csproj b/tests/BundledResources/dotnet/iOS/BundledResources.csproj new file mode 100644 index 000000000000..23b3ff0a4884 --- /dev/null +++ b/tests/BundledResources/dotnet/iOS/BundledResources.csproj @@ -0,0 +1,23 @@ + + + + net5.0 + latest + + + + + + + + + basn3p08.png + + + xamvideotest.mp4 + + + + + + diff --git a/tests/BundledResources/dotnet/macOS/BundledResources.csproj b/tests/BundledResources/dotnet/macOS/BundledResources.csproj new file mode 100644 index 000000000000..9d085a14e24e --- /dev/null +++ b/tests/BundledResources/dotnet/macOS/BundledResources.csproj @@ -0,0 +1,23 @@ + + + + net5.0 + latest + + + + + + + + + basn3p08.png + + + xamvideotest.mp4 + + + + + + diff --git a/tests/BundledResources/dotnet/tvOS/BundledResources.csproj b/tests/BundledResources/dotnet/tvOS/BundledResources.csproj new file mode 100644 index 000000000000..97ccf9b5cded --- /dev/null +++ b/tests/BundledResources/dotnet/tvOS/BundledResources.csproj @@ -0,0 +1,23 @@ + + + + net5.0 + latest + + + + + + + + + basn3p08.png + + + xamvideotest.mp4 + + + + + + diff --git a/tests/BundledResources/dotnet/watchOS/BundledResources.csproj b/tests/BundledResources/dotnet/watchOS/BundledResources.csproj new file mode 100644 index 000000000000..5bf67c0b8160 --- /dev/null +++ b/tests/BundledResources/dotnet/watchOS/BundledResources.csproj @@ -0,0 +1,23 @@ + + + + net5.0 + latest + + + + + + + + + basn3p08.png + + + xamvideotest.mp4 + + + + + + diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index fd0debca0465..c57df2b78fff 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -211,6 +211,38 @@ public void BuildBindingsTest2 (string platform) Assert.That (ad.MainModule.Resources [0].Name, Is.EqualTo ("libtest2.a"), "libtest2.a"); } + [TestCase ("iOS", "monotouch")] + [TestCase ("tvOS", "monotouch")] + [TestCase ("watchOS", "monotouch")] + [TestCase ("macOS", "xammac")] + public void BuildBundledResources (string platform, string prefix) + { + var assemblyName = "BundledResources"; + var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet"); + var project_dir = Path.Combine (dotnet_bindings_dir, platform); + var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj"); + + Clean (project_path); + CopyDotNetSupportingFiles (dotnet_bindings_dir); + var result = DotNet.AssertBuild (project_path, verbosity); + var lines = result.StandardOutput.ToString ().Split ('\n'); + // Find the resulting binding assembly from the build log + var assemblies = FilterToAssembly (lines, assemblyName); + Assert.That (assemblies, Is.Not.Empty, "Assemblies"); + // Make sure there's no other assembly confusing our logic + Assert.That (assemblies.Distinct ().Count (), Is.EqualTo (1), "Unique assemblies"); + var asm = assemblies.First (); + Assert.That (asm, Does.Exist, "Assembly existence"); + + // Verify that there's one resource in the binding assembly, and its name + var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred }); + Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (2), "2 resources"); + // Sort the resources before we assert, since we don't care about the order, and sorted order makes the asserts simpler. + var resources = ad.MainModule.Resources.OrderBy (v => v.Name).ToArray (); + Assert.That (resources [0].Name, Is.EqualTo ($"__{prefix}_content_basn3p08.png"), $"__{prefix}_content_basn3p08.png"); + Assert.That (resources [1].Name, Is.EqualTo ($"__{prefix}_content_xamvideotest.mp4"), $"__{prefix}_content_xamvideotest.mp4"); + } + [TestCase ("iOS")] [TestCase ("tvOS")] // [TestCase ("watchOS")] // No watchOS Touch.Client project for .NET yet