dotnet-watch: continue printing output to console after the app is ready (#25984)

dotnet-watch redirects standard out to detect when the app is launched and
prints these redirected messages to the console. Unfortunately once the app
is launched, redirected messages are no longer printed. This wasn't caught earlier
since ASP.NET Core is very quiet by default.

ASP.NET Core apps launched via dotnet watch do not print output to the console.

Yes. This was introduced as part of changes to dotnet-watch to launch a browser in 5.0-preview8.

Low.
This commit is contained in:
Pranav K 2020-09-16 18:53:59 -07:00 committed by GitHub
parent 8c23b53bef
commit 2921f5514a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -62,6 +62,9 @@ namespace Microsoft.DotNet.Watcher.Tools
_canLaunchBrowser = true;
_launchPath = launchPath;
_cancellationToken = cancellationToken;
// We've redirected the output, but want to ensure that it continues to appear in the user's console.
context.ProcessSpec.OnOutput += (_, eventArgs) => Console.WriteLine(eventArgs.Data);
context.ProcessSpec.OnOutput += OnOutput;
if (!_suppressBrowserRefresh)
@ -101,9 +104,6 @@ namespace Microsoft.DotNet.Watcher.Tools
private void OnOutput(object sender, DataReceivedEventArgs eventArgs)
{
// We've redirected the output, but want to ensure that it continues to appear in the user's console.
Console.WriteLine(eventArgs.Data);
if (string.IsNullOrEmpty(eventArgs.Data))
{
return;
@ -116,7 +116,6 @@ namespace Microsoft.DotNet.Watcher.Tools
var process = (Process)sender;
process.OutputDataReceived -= OnOutput;
process.CancelOutputRead();
if (!_browserLaunched)
{