diff --git a/src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs b/src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs index f9ac8e3463f9..28890852482f 100644 --- a/src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs +++ b/src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs @@ -89,7 +89,7 @@ private static void Log(string message) if (!string.IsNullOrEmpty(prefix)) { Console.ForegroundColor = ConsoleColor.DarkGray; - Console.WriteLine($"{prefix} {message}"); + Console.Error.WriteLine($"{prefix} {message}"); Console.ResetColor(); } } diff --git a/src/BuiltInTools/dotnet-watch/UI/ConsoleReporter.cs b/src/BuiltInTools/dotnet-watch/UI/ConsoleReporter.cs index 84cc357ad35a..198e518590bb 100644 --- a/src/BuiltInTools/dotnet-watch/UI/ConsoleReporter.cs +++ b/src/BuiltInTools/dotnet-watch/UI/ConsoleReporter.cs @@ -56,24 +56,24 @@ public void Report(EventId id, Emoji emoji, MessageSeverity severity, string mes { case MessageSeverity.Error: // Use stdout for error messages to preserve ordering with respect to other output. - WriteLine(console.Out, message, ConsoleColor.Red, emoji); + WriteLine(console.Error, message, ConsoleColor.Red, emoji); break; case MessageSeverity.Warning: - WriteLine(console.Out, message, ConsoleColor.Yellow, emoji); + WriteLine(console.Error, message, ConsoleColor.Yellow, emoji); break; case MessageSeverity.Output: if (!IsQuiet) { - WriteLine(console.Out, message, color: null, emoji); + WriteLine(console.Error, message, color: null, emoji); } break; case MessageSeverity.Verbose: if (IsVerbose) { - WriteLine(console.Out, message, ConsoleColor.DarkGray, emoji); + WriteLine(console.Error, message, ConsoleColor.DarkGray, emoji); } break; } diff --git a/test/dotnet-watch.Tests/ConsoleReporterTests.cs b/test/dotnet-watch.Tests/ConsoleReporterTests.cs index 7fb1c564451d..8df1601dc0dc 100644 --- a/test/dotnet-watch.Tests/ConsoleReporterTests.cs +++ b/test/dotnet-watch.Tests/ConsoleReporterTests.cs @@ -18,19 +18,19 @@ public void WritesToStandardStreams(bool suppressEmojis) var reporter = new ConsoleReporter(testConsole, verbose: true, quiet: false, suppressEmojis: suppressEmojis); reporter.Report(id: default, Emoji.Watch, MessageSeverity.Verbose, "verbose {0}"); - Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "⌚")} verbose {{0}}" + EOL, testConsole.GetOutput()); + Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "⌚")} verbose {{0}}" + EOL, testConsole.GetError()); testConsole.Clear(); reporter.Report(id: default, Emoji.Watch, MessageSeverity.Output, "out"); - Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "⌚")} out" + EOL, testConsole.GetOutput()); + Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "⌚")} out" + EOL, testConsole.GetError()); testConsole.Clear(); reporter.Report(id: default, Emoji.Warning, MessageSeverity.Warning, "warn"); - Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "⚠")} warn" + EOL, testConsole.GetOutput()); + Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "⚠")} warn" + EOL, testConsole.GetError()); testConsole.Clear(); reporter.Report(id: default, Emoji.Error, MessageSeverity.Error, "error"); - Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "❌")} error" + EOL, testConsole.GetOutput()); + Assert.Equal($"dotnet watch {(suppressEmojis ? ":" : "❌")} error" + EOL, testConsole.GetError()); testConsole.Clear(); } diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs index 2c87e8cc7469..5b23c6eb30e5 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs @@ -332,10 +332,10 @@ public void FilePath_AsProjectArgument() /// [Theory] // error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. - [InlineData("build", "MSB1003")] + [InlineData("build", "MSB1003", false)] // dotnet watch: Could not find a MSBuild project file in '...'. Specify which project to use with the --project option. - [InlineData("watch", "--project")] - public void Precedence_BuiltInCommand(string cmd, string error) + [InlineData("watch", "--project", true)] + public void Precedence_BuiltInCommand(string cmd, string error, bool errorInStdErr) { var testInstance = _testAssetsManager.CreateTestDirectory(); File.WriteAllText(Path.Join(testInstance.Path, cmd), """ @@ -348,18 +348,26 @@ public void Precedence_BuiltInCommand(string cmd, string error) """); // dotnet build -> built-in command - new DotnetCommand(Log, cmd) + var failure = new DotnetCommand(Log, cmd) .WithWorkingDirectory(testInstance.Path) .Execute() - .Should().Fail() - .And.HaveStdOutContaining(error); + .Should().Fail(); + + if (errorInStdErr) + { + failure.And.HaveStdErrContaining(error); + } + else + { + failure.And.HaveStdOutContaining(error); + } // dotnet ./build -> file-based app new DotnetCommand(Log, $"./{cmd}") - .WithWorkingDirectory(testInstance.Path) - .Execute() - .Should().Pass() - .And.HaveStdOut("hello 1"); + .WithWorkingDirectory(testInstance.Path) + .Execute() + .Should().Pass() + .And.HaveStdOut("hello 1"); // dotnet run build -> file-based app new DotnetCommand(Log, "run", cmd)