Skip to content

Support 'IfDifferent' for CopyToOutputDirectory#11052

Merged
JanKrivanek merged 4 commits intomainfrom
proto/copy-if-different
Dec 5, 2024
Merged

Support 'IfDifferent' for CopyToOutputDirectory#11052
JanKrivanek merged 4 commits intomainfrom
proto/copy-if-different

Conversation

@JanKrivanek
Copy link
Member

@JanKrivanek JanKrivanek commented Nov 29, 2024

Fixes #8743

Context

CopyToOutputDirectory currently has only PreserveNewest and Always (and Never - not considered here).
Always is unnecessery perf hit, but is only workaround for situations where destination file can change between builds (e.g. someone is copying DB, storage file, config file etc. - that can be altered during test runs).

So let's support a mode that allows copying if the file is different - doesn't have to be newer.

At the same time - Always should actually be only used in those cases - so let's make it possible to glabaly opt-in for such change in behavior.

Changes Made

  • Added 'IfDifferent' metadata and it's recognition
  • Added $(SkipUnchangedFilesOnCopyAlways) property that changes behavior of Always to IfDifferent

Testing

Tailored tests added in #11054

@JanKrivanek JanKrivanek requested a review from SimaTian December 4, 2024 18:47
@MaceWindu
Copy link
Contributor

MaceWindu commented Jan 18, 2026

It makes visual studio 2026 18.2.0 cry

System.AggregateException: Project system data flow 'UpToDateCheckImplicitConfiguredInputDataSource: 3378235' closed because of an exception.
CopyToOutputDirectory should be Always or PreserveNewest, not IfDifferent
---> (Inner Exception #0) Microsoft.Assumes+InternalErrorException: CopyToOutputDirectory should be Always or PreserveNewest, not IfDifferent
   at Microsoft.Assumes.Fail(String message)
   at Microsoft.VisualStudio.ProjectSystem.VS.UpToDate.CopyItem.<GetCopyType>g__ParseCopyType|15_0(String value)
   at Microsoft.VisualStudio.ProjectSystem.VS.UpToDate.CopyItem.GetCopyType(IImmutableDictionary`2 metadata)
   at Microsoft.VisualStudio.ProjectSystem.VS.UpToDate.UpToDateCheckImplicitConfiguredInput.<>c.<Update>b__76_24(KeyValuePair`2 pair)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at Microsoft.VisualStudio.ProjectSystem.VS.UpToDate.UpToDateCheckImplicitConfiguredInput.<>c__DisplayClass76_0.<Update>g__UpdateCopyData|9()
   at Microsoft.VisualStudio.ProjectSystem.VS.UpToDate.UpToDateCheckImplicitConfiguredInput.Update(IProjectSubscriptionUpdate jointRuleUpdate, IProjectSubscriptionUpdate sourceItemsUpdate, IProjectItemSchema projectItemSchema, IProjectCatalogSnapshot projectCatalogSnapshot)
   at Microsoft.VisualStudio.ProjectSystem.VS.UpToDate.UpToDateCheckImplicitConfiguredInputDataSource.<>c__DisplayClass12_0.<<LinkExternalInput>g__TransformAsync|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ProjectSystem.TransformBlockSlim`2.TransformBlockSlimAsync.<ProcessInputAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.ProjectSystem.DataReceivingBlockSlim`1.<ProcessInputQueueAsync>d__5.MoveNext()

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add 'IfDifferent' mode for CopyToOutputDirectory metadata

5 participants