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
13 changes: 9 additions & 4 deletions src/Workspaces/MSBuild/Core/MSBuild/BuildHostProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ public BuildHostProcess(Process process, string pipeName, ILoggerFactory? logger
_process.EnableRaisingEvents = true;
_process.Exited += Process_Exited;

_process.ErrorDataReceived += Process_ErrorDataReceived;
_process.OutputDataReceived += (_, e) => LogProcessOutput(e, "stdout");
_process.ErrorDataReceived += (_, e) => LogProcessOutput(e, "stderr");

var pipeClient = NamedPipeUtil.CreateClient(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous);
pipeClient.Connect(TimeOutMsNewProcess);
Expand All @@ -412,7 +413,11 @@ public BuildHostProcess(Process process, string pipeName, ILoggerFactory? logger
_rpcClient.Disconnected += Process_Exited;
BuildHost = new RemoteBuildHost(_rpcClient);

// Call this last so our type is fully constructed before we start firing events
// Close the standard input stream so that if any build tasks were to try reading from the console, they won't deadlock waiting for input.
_process.StandardInput.Close();

// Call Begin*ReadLine methods last so so our type is fully constructed before we start firing events.
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();
}

Expand All @@ -421,14 +426,14 @@ private void Process_Exited(object? sender, EventArgs e)
Disconnected?.Invoke(this, EventArgs.Empty);
}

private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
private void LogProcessOutput(DataReceivedEventArgs e, string outputName)
{
if (e.Data is not null)
{
lock (_processLogMessages)
_processLogMessages.AppendLine(e.Data);

_logger?.LogTrace($"Message from Process: {e.Data}");
_logger?.LogTrace($"Message on {outputName}: {e.Data}");
}
}

Expand Down
Loading