From 2921f5514a4bfd7a8966eec1e5f37804953ff1bd Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 16 Sep 2020 18:53:59 -0700 Subject: [PATCH] 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. --- src/Tools/dotnet-watch/src/LaunchBrowserFilter.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Tools/dotnet-watch/src/LaunchBrowserFilter.cs b/src/Tools/dotnet-watch/src/LaunchBrowserFilter.cs index 8e524780fd..a9fc6523c5 100644 --- a/src/Tools/dotnet-watch/src/LaunchBrowserFilter.cs +++ b/src/Tools/dotnet-watch/src/LaunchBrowserFilter.cs @@ -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) {