diff --git a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs index 5922a0ebbd8..a85e4300c9a 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs @@ -155,24 +155,30 @@ public override bool Execute() try { process.Start(); + } + catch (Exception e) + { + Log.LogErrorFromResources(nameof(Strings.Error_StaticGraphRestoreFailedToStart), e.Message); - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); - - if (SerializeGlobalProperties) - { - using var writer = new BinaryWriter(process.StandardInput.BaseStream, Encoding.UTF8, leaveOpen: true); - - WriteGlobalProperties(writer, globalProperties); - } + return false; } finally { - process.StandardInput.Close(); - Console.InputEncoding = previousConsoleInputEncoding; } + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + + if (SerializeGlobalProperties) + { + using var writer = new BinaryWriter(process.StandardInput.BaseStream, Encoding.UTF8, leaveOpen: true); + + WriteGlobalProperties(writer, globalProperties); + } + + process.StandardInput.Close(); + semaphore.Wait(_cancellationTokenSource.Token); if (!process.HasExited) @@ -224,23 +230,7 @@ e is OperationCanceledException internal string GetCommandLineArguments(Dictionary globalProperties) { // First get the command-line arguments including the global properties - string commandLineArguments = CreateArgumentString(EnumerateCommandLineArguments(SerializeGlobalProperties ? null : globalProperties)); - - if (SerializeGlobalProperties) - { - return commandLineArguments; - } - - // If the command-line arguments exceed the supported length, set the flag to serialize the global properties to the standard input stream get the - // arguments again without the global properties. - if (commandLineArguments.Length > 8000) - { - SerializeGlobalProperties = true; - - commandLineArguments = CreateArgumentString(EnumerateCommandLineArguments(globalProperties: null)); - } - - return commandLineArguments; + return CreateArgumentString(EnumerateCommandLineArguments(SerializeGlobalProperties ? null : globalProperties)); IEnumerable EnumerateCommandLineArguments(Dictionary globalProperties) { diff --git a/src/NuGet.Core/NuGet.Build.Tasks/Strings.Designer.cs b/src/NuGet.Core/NuGet.Build.Tasks/Strings.Designer.cs index 364a9cae530..203d40901fe 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/Strings.Designer.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/Strings.Designer.cs @@ -187,6 +187,15 @@ public static string Error_StaticGraphRestoreArgumentsParsingFailedUnexpectedInt } } + /// + /// Looks up a localized string similar to An error occurred starting static graph-based restore. {0}. Please file an issue at https://github.com/NuGet/Home. + /// + public static string Error_StaticGraphRestoreFailedToStart { + get { + return ResourceManager.GetString("Error_StaticGraphRestoreFailedToStart", resourceCulture); + } + } + /// /// Looks up a localized string similar to Static graph-based restore encountered an unhandled exception. Please file an issue at https://github.com/NuGet/Home. The exception was: ///{0}. diff --git a/src/NuGet.Core/NuGet.Build.Tasks/Strings.resx b/src/NuGet.Core/NuGet.Build.Tasks/Strings.resx index 33d87587e8e..1a8fd6a3297 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/Strings.resx +++ b/src/NuGet.Core/NuGet.Build.Tasks/Strings.resx @@ -225,4 +225,8 @@ An error occurred parsing command-line arguments in static graph-based restore as the first integer read, {0}, is not an allowable value. Please file an issue at https://github.com/NuGet/Home 0 - The value of the first integer read from the stream + + An error occurred starting static graph-based restore. {0}. Please file an issue at https://github.com/NuGet/Home + 0 - The exception message +