From a86f1d562418d739ad19f815fe77a140ef6c3bed Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Mar 2023 08:12:00 +0100 Subject: [PATCH] [dotnet/msbuild] Don't bundle *.xml files that matches any assemblies. Fixes #14939 and fixes #15897. This fixes a warning when documentation is enabled for a project: > The file '~/.nuget/packages/fsharp.core/6.0.0/contentFiles/any/netstandard2.1/FSharp.Core.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. This doesn't change any behavior (as the warning says, the file wasn't copied to the app bundle before either), but it makes the behavior explicitly documented and silences the warning. Fixes https://github.com/xamarin/xamarin-macios/issues/14939. Fixes https://github.com/xamarin/xamarin-macios/issues/15897. --- dotnet/BundleContents.md | 1 + .../Tasks/ComputeBundleLocationTaskBase.cs | 17 +++++++++++++++ .../BundleStructure/MacCatalyst/NoneP.xml | 0 tests/dotnet/BundleStructure/NoneN.dll | 0 tests/dotnet/BundleStructure/NoneN.xml | 0 tests/dotnet/BundleStructure/NoneO.xml | 0 tests/dotnet/BundleStructure/iOS/NoneP.xml | 0 tests/dotnet/BundleStructure/macOS/NoneP.xml | 0 tests/dotnet/BundleStructure/shared.csproj | 21 +++++++++++++++++++ tests/dotnet/BundleStructure/tvOS/NoneP.xml | 0 tests/dotnet/UnitTests/BundleStructureTest.cs | 7 +++++++ 11 files changed, 46 insertions(+) create mode 100644 tests/dotnet/BundleStructure/MacCatalyst/NoneP.xml create mode 100644 tests/dotnet/BundleStructure/NoneN.dll create mode 100644 tests/dotnet/BundleStructure/NoneN.xml create mode 100644 tests/dotnet/BundleStructure/NoneO.xml create mode 100644 tests/dotnet/BundleStructure/iOS/NoneP.xml create mode 100644 tests/dotnet/BundleStructure/macOS/NoneP.xml create mode 100644 tests/dotnet/BundleStructure/tvOS/NoneP.xml 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 (';');