Skip to content

Commit f7856c0

Browse files
authored
Request silent restore for all separate restore steps (#40148)
2 parents dc02aff + 4623228 commit f7856c0

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/Cli/dotnet/commands/RestoringCommand.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ private static RestoreCommand GetSeparateRestoreCommand(
6161
}
6262

6363
IEnumerable<string> restoreArguments = ["-target:Restore"];
64-
if (arguments != null)
65-
{
66-
(var newArgumentsToAdd, var existingArgumentsToForward) = ProcessForwardedArgumentsForSeparateRestore(arguments);
67-
restoreArguments = [.. restoreArguments, .. newArgumentsToAdd, .. existingArgumentsToForward];
68-
}
64+
(var newArgumentsToAdd, var existingArgumentsToForward) = ProcessForwardedArgumentsForSeparateRestore(arguments);
65+
restoreArguments = [.. restoreArguments, .. newArgumentsToAdd, .. existingArgumentsToForward];
6966

7067
return new RestoreCommand(restoreArguments, msbuildPath);
7168
}
@@ -84,12 +81,13 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
8481
"TargetFramework"
8582
];
8683

84+
// These arguments should lead to absolutely no output from the restore command
8785
private static readonly string[] FlagsThatTriggerSilentRestore =
88-
[
89-
"getProperty",
90-
"getItem",
91-
"getTargetResult"
92-
];
86+
[
87+
"getProperty",
88+
"getItem",
89+
"getTargetResult"
90+
];
9391

9492
// These arguments don't by themselves require that restore be run in a separate process,
9593
// but if there is a separate restore process they shouldn't be passed to it
@@ -116,12 +114,12 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
116114
// that we need to compensate for, so we might yield new arguments that should be included in the overall restore call.
117115
private static (string[] newArgumentsToAdd, string[] existingArgumentsToForward) ProcessForwardedArgumentsForSeparateRestore(IEnumerable<string> forwardedArguments)
118116
{
119-
HashSet<string> newArgumentsToAdd = new();
117+
// Separate restore should be silent in terminal logger - regardless of actual scenario
118+
HashSet<string> newArgumentsToAdd = new() { "-tlp:verbosity=quiet" };
120119
List<string> existingArgumentsToForward = new();
121120

122-
foreach (var argument in forwardedArguments)
121+
foreach (var argument in forwardedArguments ?? Enumerable.Empty<string>())
123122
{
124-
125123
if (!IsExcludedFromSeparateRestore(argument) && !IsExcludedFromRestore(argument))
126124
{
127125
existingArgumentsToForward.Add(argument);
@@ -165,6 +163,7 @@ private static bool IsExcludedFromRestore(string argument)
165163
private static bool IsExcludedFromSeparateRestore(string argument)
166164
=> FlagsToExcludeFromSeparateRestore.Any(p => argument.StartsWith(p, StringComparison.OrdinalIgnoreCase));
167165

166+
// These arguments should lead to absolutely no output from the restore command - regardless of loggers
168167
private static bool TriggersSilentSeparateRestore(string argument)
169168
=> FlagsThatTriggerSilentSeparateRestore.Any(p => argument.StartsWith(p, StringComparison.OrdinalIgnoreCase));
170169

test/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalA
5656
}
5757

5858
[Theory]
59-
[InlineData(new string[] { "-f", "tfm" }, "-target:Restore", "-property:TargetFramework=tfm")]
60-
[InlineData(new string[] { "-p:TargetFramework=tfm" }, "-target:Restore", "--property:TargetFramework=tfm")]
61-
[InlineData(new string[] { "/p:TargetFramework=tfm" }, "-target:Restore", "--property:TargetFramework=tfm")]
62-
[InlineData(new string[] { "-t:Run", "-f", "tfm" }, "-target:Restore", "-property:TargetFramework=tfm -t:Run")]
63-
[InlineData(new string[] { "/t:Run", "-f", "tfm" }, "-target:Restore", "-property:TargetFramework=tfm /t:Run")]
59+
[InlineData(new string[] { "-f", "tfm" }, "-target:Restore -tlp:verbosity=quiet", "-property:TargetFramework=tfm")]
60+
[InlineData(new string[] { "-p:TargetFramework=tfm" }, "-target:Restore -tlp:verbosity=quiet", "--property:TargetFramework=tfm")]
61+
[InlineData(new string[] { "/p:TargetFramework=tfm" }, "-target:Restore -tlp:verbosity=quiet", "--property:TargetFramework=tfm")]
62+
[InlineData(new string[] { "-t:Run", "-f", "tfm" }, "-target:Restore -tlp:verbosity=quiet", "-property:TargetFramework=tfm -t:Run")]
63+
[InlineData(new string[] { "/t:Run", "-f", "tfm" }, "-target:Restore -tlp:verbosity=quiet", "-property:TargetFramework=tfm /t:Run")]
6464
[InlineData(new string[] { "-o", "myoutput", "-f", "tfm", "-v", "diag", "/ArbitrarySwitchForMSBuild" },
65-
"-target:Restore -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild",
65+
"-target:Restore -tlp:verbosity=quiet -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild",
6666
"-property:TargetFramework=tfm -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild")]
67-
[InlineData(new string[] { "-f", "tfm", "-getItem:Compile", "-getProperty:TargetFramework", "-getTargetResult:Build" }, "-target:Restore -nologo -verbosity:quiet", "-property:TargetFramework=tfm -getItem:Compile -getProperty:TargetFramework -getTargetResult:Build")]
67+
[InlineData(new string[] { "-f", "tfm", "-getItem:Compile", "-getProperty:TargetFramework", "-getTargetResult:Build" }, "-target:Restore -tlp:verbosity=quiet -nologo -verbosity:quiet", "-property:TargetFramework=tfm -getItem:Compile -getProperty:TargetFramework -getTargetResult:Build")]
6868
public void MsbuildInvocationIsCorrectForSeparateRestore(
6969
string[] args,
7070
string expectedAdditionalArgsForRestore,

test/dotnet.Tests/dotnet-msbuild/GivenDotnetPublishInvocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void MsbuildInvocationIsCorrectForSeparateRestore(string[] args, string e
7373
command.SeparateRestoreCommand
7474
.GetArgumentsToMSBuild()
7575
.Should()
76-
.Be($"{ExpectedPrefix} -target:Restore {ExpectedProperties}");
76+
.Be($"{ExpectedPrefix} -target:Restore -tlp:verbosity=quiet {ExpectedProperties}");
7777

7878
command.GetArgumentsToMSBuild()
7979
.Should()

0 commit comments

Comments
 (0)