Skip to content

Allow extending the item metadata preserved by GetCopyToPublishDirectoryItems #57024

Open

Description

@rolfbjarne

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

  1. added
    untriaged
    on Nov 10, 2026
  2. locked and limited conversation to collaborators on Nov 10, 2026
  3. unlocked this conversation on Nov 10, 2026
  4. added
    cookie
    and removed
    untriaged
    on Nov 10, 2026
  5. github-actions commented on Nov 10, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    • 🏷️ Labels: Area-NetSDK enhancement cookie Issue Monster Loves Cookies!
    • 💻 Assignment: @marcpopMSFT | @dotnet/dotnet-cli
    • 🟩 Confidence: high - 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.

    Generated by 🏷️ Issue Triage for #57024 · copilot · auto · ~17 AIC · ⌖ ~1 AIC · ⊞ 14.6K · ◷

  6. github-actions commented on Nov 11, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · ~14 AIC · ⌖ ~15 AIC · ⊞ 13.2K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-NetSDKcookieenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions