Skip to content

Commit 913afc2

Browse files
committed
Make separate restore quiet only for terminal logger or getX commands
1 parent 620c074 commit 913afc2

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/Cli/dotnet/commands/RestoringCommand.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
106106
private static List<string> FlagsToExcludeFromSeparateRestore =
107107
ComputeFlags(FlagsToExcludeFromRestore).ToList();
108108

109+
private static List<string> FlagsThatTriggerSilentSeparateRestore =
110+
ComputeFlags(FlagsThatTriggerSilentRestore).ToList();
111+
109112
private static List<string> PropertiesToExcludeFromSeparateRestore =
110113
ComputePropertySwitches(PropertiesToExcludeFromRestore).ToList();
111114

@@ -114,16 +117,21 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
114117
// that we need to compensate for, so we might yield new arguments that should be included in the overall restore call.
115118
private static (string[] newArgumentsToAdd, string[] existingArgumentsToForward) ProcessForwardedArgumentsForSeparateRestore(IEnumerable<string> forwardedArguments)
116119
{
117-
HashSet<string> newArgumentsToAdd = new() { "-nologo", "-verbosity:quiet" };
120+
// Separate restore should be silent in terminal logger - regardless of actual scenario
121+
HashSet<string> newArgumentsToAdd = new() { "-nologo", "-tlp:verbosity=quiet" };
118122
List<string> existingArgumentsToForward = new();
119123

120124
foreach (var argument in forwardedArguments)
121125
{
122-
123126
if (!IsExcludedFromSeparateRestore(argument) && !IsExcludedFromRestore(argument))
124127
{
125128
existingArgumentsToForward.Add(argument);
126129
}
130+
131+
if (TriggersSilentSeparateRestore(argument))
132+
{
133+
newArgumentsToAdd.Add("-verbosity:quiet");
134+
}
127135
}
128136
return (newArgumentsToAdd.ToArray(), existingArgumentsToForward.ToArray());
129137
}
@@ -157,6 +165,10 @@ private static bool IsExcludedFromRestore(string argument)
157165
private static bool IsExcludedFromSeparateRestore(string argument)
158166
=> FlagsToExcludeFromSeparateRestore.Any(p => argument.StartsWith(p, StringComparison.OrdinalIgnoreCase));
159167

168+
// These arguments should lead to absolutely no output from the restore command - regardless of loggers
169+
private static bool TriggersSilentSeparateRestore(string argument)
170+
=> FlagsThatTriggerSilentSeparateRestore.Any(p => argument.StartsWith(p, StringComparison.OrdinalIgnoreCase));
171+
160172
public override int Execute()
161173
{
162174
int exitCode;

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 -nologo -verbosity:quiet", "-property:TargetFramework=tfm")]
60-
[InlineData(new string[] { "-p:TargetFramework=tfm" }, "-target:Restore -nologo -verbosity:quiet", "--property:TargetFramework=tfm")]
61-
[InlineData(new string[] { "/p:TargetFramework=tfm" }, "-target:Restore -nologo -verbosity:quiet", "--property:TargetFramework=tfm")]
62-
[InlineData(new string[] { "-t:Run", "-f", "tfm" }, "-target:Restore -nologo -verbosity:quiet", "-property:TargetFramework=tfm -t:Run")]
63-
[InlineData(new string[] { "/t:Run", "-f", "tfm" }, "-target:Restore -nologo -verbosity:quiet", "-property:TargetFramework=tfm /t:Run")]
59+
[InlineData(new string[] { "-f", "tfm" }, "-target:Restore -nologo -tlp:verbosity=quiet", "-property:TargetFramework=tfm")]
60+
[InlineData(new string[] { "-p:TargetFramework=tfm" }, "-target:Restore -nologo -tlp:verbosity=quiet", "--property:TargetFramework=tfm")]
61+
[InlineData(new string[] { "/p:TargetFramework=tfm" }, "-target:Restore -nologo -tlp:verbosity=quiet", "--property:TargetFramework=tfm")]
62+
[InlineData(new string[] { "-t:Run", "-f", "tfm" }, "-target:Restore -nologo -tlp:verbosity=quiet", "-property:TargetFramework=tfm -t:Run")]
63+
[InlineData(new string[] { "/t:Run", "-f", "tfm" }, "-target:Restore -nologo -tlp:verbosity=quiet", "-property:TargetFramework=tfm /t:Run")]
6464
[InlineData(new string[] { "-o", "myoutput", "-f", "tfm", "-v", "diag", "/ArbitrarySwitchForMSBuild" },
65-
"-target:Restore -nologo -verbosity:quiet -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild",
65+
"-target:Restore -nologo -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 -nologo -tlp:verbosity=quiet -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 -nologo -verbosity:quiet {ExpectedProperties}");
76+
.Be($"{ExpectedPrefix} -target:Restore -nologo -tlp:verbosity=quiet {ExpectedProperties}");
7777

7878
command.GetArgumentsToMSBuild()
7979
.Should()

0 commit comments

Comments
 (0)