Repository navigation
Description
Problem
GetCopyToPublishDirectoryItems limits preserved item metadata to this fixed list in Microsoft.NET.Publish.targets:
<_GCTPDIKeepMetadata>CopyToPublishDirectory;ExcludeFromSingleFile;TargetPath</_GCTPDIKeepMetadata>This drops metadata that downstream SDKs need. For example, .NET for Apple platforms uses PublishFolderType to decide where files belong in an app bundle. When a platform-neutral library provides content with this metadata, the metadata is stripped before the consuming Apple app can use it. Files may end up in the wrong location or be omitted with a warning.
See dotnet/macios#20947 for a reproduction and discussion.
The existing workaround is to set MSBuildDisableGetCopyToPublishDirectoryItemsOptimization=true in the library project. This preserves all metadata, but disables the optimization even when only one additional metadata field is needed.
Proposal
Add a public, semicolon-separated property such as MSBuildGetCopyToPublishDirectoryAdditionalItemMetadataToCopy, and append it to the existing list:
<_GCTPDIKeepMetadata>CopyToPublishDirectory;ExcludeFromSingleFile;TargetPath;$(MSBuildGetCopyToPublishDirectoryAdditionalItemMetadataToCopy)</_GCTPDIKeepMetadata>A project or shared Directory.Build.props could then opt in to preserving specific metadata:
<PropertyGroup>
<MSBuildGetCopyToPublishDirectoryAdditionalItemMetadataToCopy>$(MSBuildGetCopyToPublishDirectoryAdditionalItemMetadataToCopy);PublishFolderType</MSBuildGetCopyToPublishDirectoryAdditionalItemMetadataToCopy>
</PropertyGroup>This would retain the existing optimization while allowing SDKs and projects to preserve the metadata they need, without copying or overriding the SDK target.
Expected behavior
Additional metadata names are preserved for both the current project's items and items collected from referenced projects. Existing behavior remains unchanged when the property is unset.
The property must be set in each project where filtering occurs, including intermediate referenced projects. Setting it only in the consuming app would not recover metadata already discarded by a library. Consumers could use shared configuration or pass it as a global property when traversing references.
Note
This issue was generated with GitHub Copilot.
Activity
github-actions commentedon Nov 10, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@marcpopMSFT| @dotnet/dotnet-clihigh- Issue targets Microsoft.NET.Publish.targets, which CODEOWNERS places under Area-NetSDK owned by the dotnet-cli team.➡️ Summary: Requests a public property to extend the metadata list preserved by GetCopyToPublishDirectoryItems, so metadata like PublishFolderType survives. Review the proposed property name and implement the small targets change with tests.
github-actions commentedon Nov 11, 2026
🍪 Issue Monster selected this for Copilot
I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪