From 669a21e77c571cbf6d37368052dd6a238bee34b5 Mon Sep 17 00:00:00 2001 From: Ben Villalobos <4691428+BenVillalobos@users.noreply.github.com> Date: Tue, 27 Jul 2021 01:17:56 -0700 Subject: [PATCH 1/2] Skip Updating CopyComplete Marker When Not Necessary (#6698) Fixes #https://github.com/dotnet/msbuild/issues/6576 ### Context https://github.com/dotnet/msbuild/issues/6576 revealed that the `.copycomplete` file marker is updated even when the `Copy` task in `_GetCopyFilesMarkedLocal` doesn't _actually_ copy anything. This can mess with incremental builds. ### Changes Made This change adds an output parameter, `CopiedAtLeastOneFile` to the `Copy` task that the `Touch` task is now conditioned off of. ### Testing Tested local builds ### Notes This could also be done by having an ITaskItem[] that contains all files that were actually copied. Then the touch task could check if that item were empty. I opted for the straightforward route since the ITaskItem[] solution isn't needed yet, and this implementation can easily be changed when we do need that. Co-authored-by: Forgind --- .../net/Microsoft.Build.Tasks.Core.cs | 2 ++ .../netstandard/Microsoft.Build.Tasks.Core.cs | 2 ++ src/Tasks/Copy.cs | 6 ++++++ src/Tasks/Microsoft.Common.CurrentVersion.targets | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs index c94de3e3688..0e39d539eba 100644 --- a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs +++ b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs @@ -207,6 +207,8 @@ public Copy() { } public Microsoft.Build.Framework.ITaskItem[] SourceFiles { get { throw null; } set { } } public bool UseHardlinksIfPossible { get { throw null; } set { } } public bool UseSymboliclinksIfPossible { get { throw null; } set { } } + [Microsoft.Build.Framework.OutputAttribute] + public bool WroteAtLeastOneFile { get { throw null; } } public void Cancel() { } public override bool Execute() { throw null; } } diff --git a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs index 27ba53105be..18bd0c97245 100644 --- a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs +++ b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs @@ -137,6 +137,8 @@ public Copy() { } public Microsoft.Build.Framework.ITaskItem[] SourceFiles { get { throw null; } set { } } public bool UseHardlinksIfPossible { get { throw null; } set { } } public bool UseSymboliclinksIfPossible { get { throw null; } set { } } + [Microsoft.Build.Framework.OutputAttribute] + public bool WroteAtLeastOneFile { get { throw null; } } public void Cancel() { } public override bool Execute() { throw null; } } diff --git a/src/Tasks/Copy.cs b/src/Tasks/Copy.cs index ba793b673d6..e22b7cc2372 100644 --- a/src/Tasks/Copy.cs +++ b/src/Tasks/Copy.cs @@ -139,6 +139,9 @@ public Copy() [Output] public ITaskItem[] CopiedFiles { get; private set; } + [Output] + public bool WroteAtLeastOneFile { get; private set; } + /// /// Whether to overwrite files in the destination /// that have the read-only attribute set. @@ -298,6 +301,9 @@ FileState destinationFileState // The destination file File.Copy(sourceFileState.Name, destinationFileState.Name, true); } + + // Files were successfully copied or linked. Those are equivalent here. + WroteAtLeastOneFile = true; destinationFileState.Reset(); diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index 94eb7fac321..0f2b8dea415 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -4690,6 +4690,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. + @@ -4699,7 +4700,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. input to projects that reference this one. --> + Condition="'@(ReferencesCopiedInThisBuild)' != '' and '$(WroteAtLeastOneFile)' == 'true'"> From f8a13d0144b8b9d6ccbe865a66d75379b2005987 Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Thu, 16 Sep 2021 15:22:44 -0500 Subject: [PATCH 2/2] Version bump to 16.11.1 --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index c46fb09fd9a..20873217009 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 16.11.0 + 16.11.1 release 15.1.0.0 preview