diff --git a/dotnet/BundleContents.md b/dotnet/BundleContents.md index cb8e45a866fc..54d3034ad1ce 100644 --- a/dotnet/BundleContents.md +++ b/dotnet/BundleContents.md @@ -53,6 +53,7 @@ wrong, then developers can override the target location by: * If the `PackageDebugSymbols` is set to something else: `PublishFolderType=None`. * If the `PackageDebugSymbols` is not set: `PublishFolderType=None` for release builds, `PublishFolderType=Assembly` otherwise. +* \*.xml: if there's an assembly with the same name (\*.exe or \*.dll), then `PublishFolderType=None` * A \*.resources directory or a \*.resources.zip file next to an assembly with the same name is treated as a third-party binding (`PublishFolderType=AppleBindingResourcePackage`), and we handle it as such diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeBundleLocationTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeBundleLocationTaskBase.cs index 6b9dc05b6e17..3f09e8a569d3 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeBundleLocationTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeBundleLocationTaskBase.cs @@ -294,6 +294,23 @@ PublishFolderType ComputePublishFolderType (IList items, ITaskItem it return PackageSymbols ? PublishFolderType.Assembly : PublishFolderType.None; } + // If an xml file matches the filename of any assembly, then treat that xml file as PublishFolderType=None + if (filename.EndsWith (".xml", StringComparison.OrdinalIgnoreCase)) { + var baseName = Path.GetFileNameWithoutExtension (filename); + if (items.Any (v => { + var fn = Path.GetFileName (v.ItemSpec); + if (fn.Length != baseName.Length + 4) + return false; + + if (!(fn.EndsWith (".exe", StringComparison.OrdinalIgnoreCase) || fn.EndsWith (".dll", StringComparison.OrdinalIgnoreCase))) + return false; + + return fn.StartsWith (baseName, StringComparison.OrdinalIgnoreCase); + })) { + return PublishFolderType.None; + } + } + // Binding resource package (*.resources / *.resources.zip) if (IsBindingResourcePackage (filename, out var type)) return type; diff --git a/tests/dotnet/BundleStructure/MacCatalyst/NoneP.xml b/tests/dotnet/BundleStructure/MacCatalyst/NoneP.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/BundleStructure/NoneN.dll b/tests/dotnet/BundleStructure/NoneN.dll new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/BundleStructure/NoneN.xml b/tests/dotnet/BundleStructure/NoneN.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/BundleStructure/NoneO.xml b/tests/dotnet/BundleStructure/NoneO.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/BundleStructure/iOS/NoneP.xml b/tests/dotnet/BundleStructure/iOS/NoneP.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/BundleStructure/macOS/NoneP.xml b/tests/dotnet/BundleStructure/macOS/NoneP.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/BundleStructure/shared.csproj b/tests/dotnet/BundleStructure/shared.csproj index e80f1ff016d4..823ff9031185 100644 --- a/tests/dotnet/BundleStructure/shared.csproj +++ b/tests/dotnet/BundleStructure/shared.csproj @@ -111,6 +111,27 @@ PreserveNewest + + + + PreserveNewest + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + PreserveNewest + diff --git a/tests/dotnet/BundleStructure/tvOS/NoneP.xml b/tests/dotnet/BundleStructure/tvOS/NoneP.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/dotnet/UnitTests/BundleStructureTest.cs b/tests/dotnet/UnitTests/BundleStructureTest.cs index ce71def72e1a..ed23cfccc1e5 100644 --- a/tests/dotnet/UnitTests/BundleStructureTest.cs +++ b/tests/dotnet/UnitTests/BundleStructureTest.cs @@ -136,6 +136,12 @@ void CheckAppBundleContents (ApplePlatform platform, string appPath, string [] r expectedFiles.Add (Path.Combine (resourcesDirectory, "basn3p08_with_loc.png")); expectedFiles.Add (Path.Combine (resourcesDirectory, "iTunesArtwork.jpg")); + // NoneN.dll: bundled (assembly) - but the xml file next to it should not be bundled. + expectedFiles.Add (Path.Combine (assemblyDirectory, "NoneN.dll")); + + // NoneP.dll: bundled (assembly) - but the xml file with the same base name should not be bundled. + expectedFiles.Add (Path.Combine (assemblyDirectory, "NoneP.dll")); + // UnknownA.bin: None expectedFiles.Add (Path.Combine (assemblyDirectory, "UnknownB.bin")); // UnknownB.bin: Assembly expectedFiles.Add (Path.Combine (resourcesDirectory, "UnknownC.bin")); // UnknownC.bin: Resource @@ -578,6 +584,7 @@ public void Build (ApplePlatform platform, string runtimeIdentifiers, CodeSignat $"The file '{Path.Combine (project_dir, platformString, "NoneM.unknown")}' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.", $"The file '{Path.Combine (project_dir, platformString, "Sub", "NoneG.txt")}' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.", $"The file '{Path.Combine (project_dir, "NoneH.txt")}' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.", + $"The file '{Path.Combine (project_dir, "NoneO.xml")}' does not specify a 'PublishFolderType' metadata, and a default value could not be calculated. The file will not be copied to the app bundle.", }.ToList (); var rids = runtimeIdentifiers.Split (';');