From 15c9afff2bab4ffa573a3e2cbc77c46918572012 Mon Sep 17 00:00:00 2001 From: Jeff Kluge Date: Tue, 10 Oct 2023 13:00:58 -0700 Subject: [PATCH] Address feedback --- src/NuGet.Core/NuGet.Build.Tasks.Console/Program.cs | 2 +- .../NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/NuGet.Core/NuGet.Build.Tasks.Console/Program.cs b/src/NuGet.Core/NuGet.Build.Tasks.Console/Program.cs index 242a1e1e3e1..8827ff8ab70 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks.Console/Program.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks.Console/Program.cs @@ -188,7 +188,7 @@ internal static bool TryParseArguments(string[] args, Func getStream, Te else { #endif - using var reader = new BinaryReader(getStream(), Encoding.UTF8, leaveOpen: true); + using var reader = new BinaryReader(getStream(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true), leaveOpen: true); if (!TryDeserializeGlobalProperties(errorWriter, reader, out globalProperties)) { diff --git a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs index a85e4300c9a..34394813892 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs @@ -105,6 +105,8 @@ public override bool Execute() Dictionary globalProperties = GetGlobalProperties(); + Encoding utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); + using (var semaphore = new SemaphoreSlim(initialCount: 0, maxCount: 1)) using (var loggingQueue = new TaskLoggingQueue(Log)) using (var process = new Process()) @@ -121,7 +123,7 @@ public override bool Execute() RedirectStandardInput = true, RedirectStandardOutput = true, #if !NETFRAMEWORK - StandardInputEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), + StandardInputEncoding = utf8Encoding, #endif UseShellExecute = false, WorkingDirectory = Environment.CurrentDirectory, @@ -150,7 +152,7 @@ public override bool Execute() Encoding previousConsoleInputEncoding = Console.InputEncoding; // Set the input encoding to UTF8 without a byte order mark, the spawned process will use this encoding on .NET Framework - Console.InputEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); + Console.InputEncoding = utf8Encoding; try { @@ -172,7 +174,7 @@ public override bool Execute() if (SerializeGlobalProperties) { - using var writer = new BinaryWriter(process.StandardInput.BaseStream, Encoding.UTF8, leaveOpen: true); + using var writer = new BinaryWriter(process.StandardInput.BaseStream, utf8Encoding, leaveOpen: true); WriteGlobalProperties(writer, globalProperties); }