Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/CopyOnWrite/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class Copy : Task, ICancelableTask
internal const string AlwaysOverwriteReadOnlyFilesEnvVar = "MSBUILDALWAYSOVERWRITEREADONLYFILES";
private static readonly bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;

// Escape hatch taken from MSBuild Traits.cs that allows turning off delete-before-copy logic.
private static readonly bool CopyWithoutDeleteEscapeHatch = Environment.GetEnvironmentVariable("MSBUILDCOPYWITHOUTDELETE") == "1";

// Default parallelism determined empirically - times below are in seconds spent in the Copy task building this repo
// with "build -skiptests -rebuild -configuration Release /ds" (with hack to build.ps1 to disable creating selfhost
// build for non-selfhost first build; implies first running build in repo to pull packages and create selfhost)
Expand Down Expand Up @@ -265,7 +268,8 @@ private void LogDiagnostic(string message, params object[] messageArgs)
MakeFileWriteable(destinationFileState, true);
}

if (destinationFileState.FileExists &&
if (!CopyWithoutDeleteEscapeHatch &&
destinationFileState.FileExists &&
!destinationFileState.IsReadOnly)
{
FileUtilities.DeleteNoThrow(destinationFileState.Name);
Expand Down