From 1ebcc5ee011ba567e80e963874878de177c49caa Mon Sep 17 00:00:00 2001 From: Christian Sidak Date: Thu, 9 Apr 2026 19:29:43 -0700 Subject: [PATCH] Write launch settings message to stderr instead of stdout The "Using launch settings from ..." message was written to stdout via Reporter.Output.WriteLine, which pollutes program output and breaks piping (e.g. dotnet run > output.json produces invalid JSON). Changed to Reporter.Error.WriteLine in both RunCommand.cs and SolutionAndProjectUtility.cs so the message goes to stderr, consistent with other diagnostic messages. Updated tests to check StdErr for this message. Fixes #45640 --- src/Cli/dotnet/Commands/Run/RunCommand.cs | 2 +- .../Test/MTP/SolutionAndProjectUtility.cs | 2 +- .../Test/GivenDotnetTestBuildsAndRunsTests.cs | 32 ++++++++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Cli/dotnet/Commands/Run/RunCommand.cs b/src/Cli/dotnet/Commands/Run/RunCommand.cs index ee2557bd7e9c..9c72a984d102 100644 --- a/src/Cli/dotnet/Commands/Run/RunCommand.cs +++ b/src/Cli/dotnet/Commands/Run/RunCommand.cs @@ -469,7 +469,7 @@ internal LaunchProfileParseResult ReadLaunchProfileSettings() if (!RunCommandVerbosity.IsQuiet()) { - Reporter.Output.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); + Reporter.Error.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); } return LaunchSettings.ReadProfileSettingsFromFile(launchSettingsPath, LaunchProfile); diff --git a/src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs b/src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs index d39b57871027..6135b177850c 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs @@ -403,7 +403,7 @@ static RunProperties GetRunProperties(ProjectInstance project) // If buildOptions.Verbosity is null, we still want to print the message. if (buildOptions.Verbosity != VerbosityOptions.quiet) { - Reporter.Output.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); + Reporter.Error.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); } var result = LaunchSettings.ReadProfileSettingsFromFile(launchSettingsPath, profileName); diff --git a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs index 330d27eec694..f37bce554551 100644 --- a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs +++ b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs @@ -158,10 +158,12 @@ public void RunTestProjectWithTestsAndLaunchSettings_ShouldReturnExitCodeSuccess if (!SdkTestContext.IsLocalized()) { - result.StdOut + result.StdErr .Should().Contain("Using launch settings from") - .And.Contain(runJson ? "TestProjectWithLaunchSettings.run.json..." : $"Properties{Path.DirectorySeparatorChar}launchSettings.json...") - .And.Contain("Test run summary: Passed!") + .And.Contain(runJson ? "TestProjectWithLaunchSettings.run.json..." : $"Properties{Path.DirectorySeparatorChar}launchSettings.json..."); + + result.StdOut + .Should().Contain("Test run summary: Passed!") .And.Contain("MY_VARIABLE_FROM_LAUNCH_SETTINGS=TestValue1") .And.Contain("skipped Test1") .And.Contain("total: 2") @@ -217,10 +219,12 @@ public void RunTestProjectWithTestsAndLaunchSettingsAndExecutableProfile() .Execute( "-c", TestingConstants.Debug); - result.StdOut.Should() + result.StdErr.Should() .Contain("Using launch settings from") - .And.Contain($"Properties{Path.DirectorySeparatorChar}launchSettings.json...") - .And.Contain("FAILED to find argument from launchSettings.json"); + .And.Contain($"Properties{Path.DirectorySeparatorChar}launchSettings.json..."); + + result.StdOut.Should() + .Contain("FAILED to find argument from launchSettings.json"); } [InlineData(TestingConstants.Debug)] @@ -237,10 +241,12 @@ public void RunTestProjectWithTestsAndNoLaunchSettingsArguments_ShouldReturnExit "-c", configuration, "--no-launch-profile-arguments", "true"); - result.StdOut.Should() + result.StdErr.Should() .Contain("Using launch settings from") - .And.Contain($"Properties{Path.DirectorySeparatorChar}launchSettings.json...") - .And.Contain("FAILED to find argument from launchSettings.json"); + .And.Contain($"Properties{Path.DirectorySeparatorChar}launchSettings.json..."); + + result.StdOut.Should() + .Contain("FAILED to find argument from launchSettings.json"); } [InlineData(TestingConstants.Debug)] @@ -575,10 +581,12 @@ public void RunTestProjectWithEnvVariable(string configuration) if (!SdkTestContext.IsLocalized()) { - result.StdOut + result.StdErr .Should().Contain("Using launch settings from") - .And.Contain($"Properties{Path.DirectorySeparatorChar}launchSettings.json...") - .And.Contain("Test run summary: Failed!") + .And.Contain($"Properties{Path.DirectorySeparatorChar}launchSettings.json..."); + + result.StdOut + .Should().Contain("Test run summary: Failed!") .And.Contain("total: 1") .And.Contain("succeeded: 0") .And.Contain("failed: 1")