Skip to content

Commit 230fa2a

Browse files
baronfelCopilot
andauthored
ensure that the run commands operates on minimal verbosity by default (#50114)
Co-authored-by: Copilot <[email protected]>
1 parent a9c5b0c commit 230fa2a

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/Cli/dotnet/Commands/Run/RunCommand.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public class RunCommand
6969
public string? LaunchProfile { get; }
7070
public bool NoLaunchProfile { get; }
7171

72+
/// <summary>
73+
/// The verbosity of the run-portion of this command specifically. If implicit builds are performed, they will always happen
74+
/// at a quiet verbosity by default, but it's important that we enable separate verbosity for the run command itself.
75+
/// </summary>
76+
public VerbosityOptions RunCommandVerbosity { get; private set; }
77+
7278
/// <summary>
7379
/// True to ignore command line arguments specified by launch profile.
7480
/// </summary>
@@ -208,7 +214,7 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel
208214
return true;
209215
}
210216

211-
if (MSBuildArgs.Verbosity?.IsQuiet() != true)
217+
if (!RunCommandVerbosity.IsQuiet())
212218
{
213219
Reporter.Output.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
214220
}
@@ -339,11 +345,20 @@ private MSBuildArgs SetupSilentBuildArgs(MSBuildArgs msbuildArgs)
339345
{
340346
msbuildArgs = msbuildArgs.CloneWithAdditionalArgs("-nologo");
341347

342-
if (msbuildArgs.Verbosity is null)
348+
if (msbuildArgs.Verbosity is VerbosityOptions userVerbosity)
349+
{
350+
// if the user had a desired verbosity, we use that for the run command
351+
RunCommandVerbosity = userVerbosity;
352+
return msbuildArgs;
353+
}
354+
else
343355
{
356+
// Apply defaults if the user didn't expressly set the verbosity.
357+
// Setting RunCommandVerbosity to minimal ensures that we keep the previous launchsettings
358+
// and related diagnostics messages on by default.
359+
RunCommandVerbosity = VerbosityOptions.minimal;
344360
return msbuildArgs.CloneWithVerbosity(VerbosityOptions.quiet);
345361
}
346-
return msbuildArgs;
347362
}
348363

349364
internal ICommand GetTargetCommand(Func<ProjectCollection, ProjectInstance>? projectFactory)
@@ -356,7 +371,7 @@ internal ICommand GetTargetCommand(Func<ProjectCollection, ProjectInstance>? pro
356371
return CreateCommandForCscBuiltProgram(EntryPointFileFullPath);
357372
}
358373

359-
FacadeLogger? logger = LoggerUtility.DetermineBinlogger([..MSBuildArgs.OtherMSBuildArgs], "dotnet-run");
374+
FacadeLogger? logger = LoggerUtility.DetermineBinlogger([.. MSBuildArgs.OtherMSBuildArgs], "dotnet-run");
360375
var project = EvaluateProject(ProjectFileFullPath, projectFactory, MSBuildArgs, logger);
361376
ValidatePreconditions(project);
362377
InvokeRunArgumentsTarget(project, NoBuild, logger, MSBuildArgs);

test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,8 @@ Hello from Program
15971597
Message: ''
15981598
""");
15991599

1600-
new DotnetCommand(Log, "run", "Program.cs")
1600+
// quiet runs here so that launch-profile useage messages don't impact test assertions
1601+
new DotnetCommand(Log, "run", "-v", "q", "Program.cs")
16011602
.WithWorkingDirectory(testInstance.Path)
16021603
.Execute()
16031604
.Should().Pass()
@@ -1607,7 +1608,7 @@ Hello from Program
16071608
Message: 'PropertiesLaunchSettingsJson1'
16081609
""");
16091610

1610-
new DotnetCommand(Log, "run", "-lp", "TestProfile2", "Program.cs")
1611+
new DotnetCommand(Log, "run", "-v", "q", "-lp", "TestProfile2", "Program.cs")
16111612
.WithWorkingDirectory(testInstance.Path)
16121613
.Execute()
16131614
.Should().Pass()
@@ -1634,7 +1635,8 @@ public void LaunchProfile_Multiple()
16341635
File.WriteAllText(Path.Join(testInstance.Path, "Second.cs"), source);
16351636
File.WriteAllText(Path.Join(testInstance.Path, "Second.run.json"), s_launchSettings.Replace("TestProfileMessage", "Second"));
16361637

1637-
new DotnetCommand(Log, "run", "First.cs")
1638+
// do these runs with quiet verbosity so that default run output doesn't impact the tests
1639+
new DotnetCommand(Log, "run", "-v", "q", "First.cs")
16381640
.WithWorkingDirectory(testInstance.Path)
16391641
.Execute()
16401642
.Should().Pass()
@@ -1643,7 +1645,7 @@ Hello from First
16431645
Message: 'First1'
16441646
""");
16451647

1646-
new DotnetCommand(Log, "run", "Second.cs")
1648+
new DotnetCommand(Log, "run", "-v", "q", "Second.cs")
16471649
.WithWorkingDirectory(testInstance.Path)
16481650
.Execute()
16491651
.Should().Pass()

0 commit comments

Comments
 (0)