Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet/msbuild] Don't bundle *.xml files that match any assemblies. Fixes #14939 and fixes #15897. #17908

Merged
merged 1 commit into from Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/BundleContents.md
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
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
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
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