Skip to content

Commit 9f15c7b

Browse files
Copilotbaronfel
andcommitted
Fix first-run experience to output to stderr instead of stdout
Co-authored-by: baronfel <[email protected]>
1 parent 18c8bff commit 9f15c7b

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// See https://aka.ms/new-console-template for more information
2+
Console.WriteLine("Hello, World!");

sdk.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

src/Cli/dotnet/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private static void ConfigureDotNetForFirstTimeUse(
378378
var environmentPath = EnvironmentPathFactory.CreateEnvironmentPath(isDotnetBeingInvokedFromNativeInstaller, environmentProvider);
379379
_ = new DotNetCommandFactory(alwaysRunOutOfProc: true);
380380
var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
381-
var reporter = Reporter.Output;
381+
var reporter = Reporter.Error;
382382
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
383383
firstTimeUseNoticeSentinel,
384384
aspNetCertificateSentinel,

test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ public void ItShowsTheAppropriateMessageToTheUser()
118118
.And.NotContain("Restore completed in");
119119
}
120120

121+
[WindowsOnlyFact]
122+
public void FirstRunExperienceMessagesShouldGoToStdErr()
123+
{
124+
// This test ensures that first-run experience messages go to stderr,
125+
// not stdout, to avoid interfering with completion commands and other
126+
// tools that parse stdout. See: https://github.com/dotnet/sdk/issues/50444
127+
var expectedVersion = GetDotnetVersion();
128+
129+
// StdErr should contain first-run messages
130+
_fixture.FirstDotnetVerbUseCommandResult.StdErr
131+
.Should()
132+
.ContainVisuallySameFragment(string.Format(
133+
Configurer.LocalizableStrings.FirstTimeMessageWelcome,
134+
DotnetFirstTimeUseConfigurer.ParseDotNetVersion(expectedVersion),
135+
expectedVersion))
136+
.And.ContainVisuallySameFragment(Configurer.LocalizableStrings.FirstTimeMessageMoreInformation);
137+
138+
// StdOut should NOT contain first-run messages (they should only be in stderr)
139+
_fixture.FirstDotnetVerbUseCommandResult.StdOut
140+
.Should()
141+
.NotContain("Welcome to .NET")
142+
.And.NotContain("Write your first app");
143+
}
144+
121145
[Fact]
122146
public void ItCreatesAFirstUseSentinelFileUnderTheDotDotNetFolder()
123147
{
@@ -164,7 +188,7 @@ public void ItShowsTheTelemetryNoticeWhenInvokingACommandAfterInternalReportInst
164188

165189
var expectedVersion = GetDotnetVersion();
166190

167-
result.StdOut
191+
result.StdErr
168192
.Should()
169193
.ContainVisuallySameFragment(string.Format(
170194
Configurer.LocalizableStrings.FirstTimeMessageWelcome,

0 commit comments

Comments
 (0)