Skip to content

Commit

Permalink
[dotnet/msbuild] Don't bundle *.xml files that matches any assemblies.
Browse files Browse the repository at this point in the history
…Fixes xamarin#14939 and fixes xamarin#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 xamarin#14939.
Fixes xamarin#15897.
  • Loading branch information
rolfbjarne committed Mar 27, 2023
1 parent b18212a commit a86f1d5
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions dotnet/BundleContents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ PublishFolderType ComputePublishFolderType (IList<ITaskItem> 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;
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions tests/dotnet/BundleStructure/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@
<!-- Bundled, not linked with, install_name_tool must have been executed -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<!-- Assembly: should be copied, but the xml file next to it should not (and there shouldn't be any warnings either) -->
<None Include="../NoneN.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="../NoneN.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<!-- Lone xml file (no sibling assembly): should not be copied, and a warning should be printed -->
<None Include="../NoneO.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<!-- Assembly: should be copied, but the xml file with the same base name (even though it's in a different directory) should not (and there shouldn't be any warnings either) -->
<None Include="../NoneP.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="NoneP.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions tests/dotnet/UnitTests/BundleStructureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (';');
Expand Down

0 comments on commit a86f1d5

Please sign in to comment.