Skip to content

Audit usages of PreserveNewest/Always metadata to ensure support for IfDifferent #51829

@JanKrivanek

Description

@JanKrivanek

Derived from: #51826 (comment) (by @baronfel)

Context

dotnet/msbuild#11052 introduced support of 'IfDifferent' for CopyToOutputDirectory metadata. This mostly helps avoid usages of 'Always' in cases where timestamp check is not sufficient (e.g. some version control systems reverts or build/publish outputs actually being used and altered during debugging).

Without complementing change in sdk, we would have confusing mix of the metadata being supported just in some cases. Also we cannot expose it in VS (as it possibly could lead to edits that wouldn't be fully supported down the road) - which limits disccoverability:

Image

Why do we want IfDifferent?

To stear users from usages of 'Always' copy metdata - as that is one of the main factors preventing incrementality of builds

Alternatives?

Mentioned MSBuild PR introduced opt-in mechanism to flip copy-always behavior to if-different behavior - via setting $(SkipUnchangedFilesOnCopyAlways) property. So we can start start setting it for projects targetting newer TFMs. But again it'd be helpful to have complementing change in sdk as well.

What is suggested to be done

  • Revisit all instances of logic that splits items based on CopyToOutputDirectory/CopyToPublishDirectory/Copy... metadata values - to account for the 'IfDifferent' value
  • Revisit the usages of the logic where we set the value of metadata - if we should actualy replace instances of 'PreserveNewest' with 'IfDifferent'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions