diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index 402fe6eb556..9fb1d1cc7fc 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -26,8 +26,9 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t ### 17.8 - [[RAR] Don't do I/O on SDK-provided references](https://github.com/dotnet/msbuild/pull/8688) - [Delete destination file before copy](https://github.com/dotnet/msbuild/pull/8685) -- [New serialization approach for transferring build exceptions between processes](https://github.com/dotnet/msbuild/pull/8779) - [Moving from SHA1 to SHA256 for Hash task](https://github.com/dotnet/msbuild/pull/8812) +- [Deprecating custom derived BuildEventArgs](https://github.com/dotnet/msbuild/pull/8917) - feature can be opted out only if [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) is allowed at runtime by editing `MSBuild.runtimeconfig.json` + ### 17.6 - [Parse invalid property under target](https://github.com/dotnet/msbuild/pull/8190) @@ -68,4 +69,4 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t - [Optimized immutable files up to date checks](https://github.com/dotnet/msbuild/pull/6974) - [Add Microsoft.IO.Redist for directory enumeration](https://github.com/dotnet/msbuild/pull/6771) - [Process-wide caching of ToolsetConfigurationSection](https://github.com/dotnet/msbuild/pull/6832) -- [Normalize RAR output paths](https://github.com/dotnet/msbuild/pull/6533) \ No newline at end of file +- [Normalize RAR output paths](https://github.com/dotnet/msbuild/pull/6533) diff --git a/src/Build/BackEnd/Node/OutOfProcNode.cs b/src/Build/BackEnd/Node/OutOfProcNode.cs index c5d8282d5bb..7757598b2cd 100644 --- a/src/Build/BackEnd/Node/OutOfProcNode.cs +++ b/src/Build/BackEnd/Node/OutOfProcNode.cs @@ -587,7 +587,8 @@ private void SendPacket(INodePacket packet) #if RUNTIME_TYPE_NETCORE if (packet is LogMessagePacketBase logMessage && logMessage.EventType == LoggingEventType.CustomEvent - && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_8) + && + (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_8) || !Traits.Instance.EscapeHatches.IsBinaryFormatterSerializationAllowed) && Traits.Instance.EscapeHatches.EnableWarningOnCustomBuildEvent) { BuildEventArgs buildEvent = logMessage.NodeBuildEvent.Value.Value; diff --git a/src/Build/Instance/TaskFactories/TaskHostTask.cs b/src/Build/Instance/TaskFactories/TaskHostTask.cs index 4fb2fe61f8d..a77509a9120 100644 --- a/src/Build/Instance/TaskFactories/TaskHostTask.cs +++ b/src/Build/Instance/TaskFactories/TaskHostTask.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -436,7 +436,7 @@ private void HandlePacket(INodePacket packet, out bool taskFinished) private void HandleTaskHostTaskComplete(TaskHostTaskComplete taskHostTaskComplete) { #if FEATURE_REPORTFILEACCESSES - if (taskHostTaskComplete.FileAccessData.Count > 0) + if (taskHostTaskComplete.FileAccessData?.Count > 0) { IFileAccessManager fileAccessManager = ((IFileAccessManager)_buildComponentHost.GetComponent(BuildComponentType.FileAccessManager)); foreach (FileAccessData fileAccessData in taskHostTaskComplete.FileAccessData) diff --git a/src/Framework/BinaryTranslator.cs b/src/Framework/BinaryTranslator.cs index 207390427d6..f5585995802 100644 --- a/src/Framework/BinaryTranslator.cs +++ b/src/Framework/BinaryTranslator.cs @@ -582,12 +582,6 @@ public void TranslateDotNet(ref T value) public void TranslateException(ref Exception value) { - if (!ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_8)) - { - TranslateDotNet(ref value); - return; - } - if (!TranslateNullable(value)) { return; @@ -1291,12 +1285,6 @@ public void TranslateDotNet(ref T value) public void TranslateException(ref Exception value) { - if (!ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_8)) - { - TranslateDotNet(ref value); - return; - } - if (!TranslateNullable(value)) { return; diff --git a/src/Framework/Traits.cs b/src/Framework/Traits.cs index 9be74ea1bc8..04b2fc90237 100644 --- a/src/Framework/Traits.cs +++ b/src/Framework/Traits.cs @@ -188,6 +188,11 @@ internal class EscapeHatches /// public readonly bool AlwaysDoImmutableFilesUpToDateCheck = Environment.GetEnvironmentVariable("MSBUILDDONOTCACHEMODIFICATIONTIME") == "1"; + /// + /// When copying over an existing file, copy directly into the existing file rather than deleting and recreating. + /// + public readonly bool CopyWithoutDelete = Environment.GetEnvironmentVariable("MSBUILDCOPYWITHOUTDELETE") == "1"; + /// /// Emit events for project imports. /// @@ -395,6 +400,27 @@ public bool EnableWarningOnCustomBuildEvent } } + private bool? _isBinaryFormatterSerializationAllowed; + public bool IsBinaryFormatterSerializationAllowed + { + get + { + if (!_isBinaryFormatterSerializationAllowed.HasValue) + { +#if RUNTIME_TYPE_NETCORE + AppContext.TryGetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", + out bool enabled); + _isBinaryFormatterSerializationAllowed = enabled; +#else + _isBinaryFormatterSerializationAllowed = true; +#endif + } + + return _isBinaryFormatterSerializationAllowed.Value; + } + } + + private static bool? ParseNullableBoolFromEnvironmentVariable(string environmentVariable) { var value = Environment.GetEnvironmentVariable(environmentVariable); diff --git a/src/Shared/TaskHostTaskComplete.cs b/src/Shared/TaskHostTaskComplete.cs index 599b5bfe9db..f493f43175f 100644 --- a/src/Shared/TaskHostTaskComplete.cs +++ b/src/Shared/TaskHostTaskComplete.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -245,6 +245,9 @@ public void Translate(ITranslator translator) translator.TranslateDictionary(ref _buildProcessEnvironment, StringComparer.OrdinalIgnoreCase); #if FEATURE_REPORTFILEACCESSES translator.Translate(ref _fileAccessData); +#else + bool hasFileAccessData = false; + translator.Translate(ref hasFileAccessData); #endif } diff --git a/src/Tasks/Copy.cs b/src/Tasks/Copy.cs index 0485ae97b36..606677f3305 100644 --- a/src/Tasks/Copy.cs +++ b/src/Tasks/Copy.cs @@ -285,7 +285,10 @@ private void LogAlwaysRetryDiagnosticFromResources(string messageResourceName, p MakeFileWriteable(destinationFileState, true); } - if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_8) && destinationFileState.FileExists && !destinationFileState.IsReadOnly) + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_8) && + Traits.Instance.EscapeHatches.CopyWithoutDelete != true && + destinationFileState.FileExists && + !destinationFileState.IsReadOnly) { FileUtilities.DeleteNoThrow(destinationFileState.Name); }