Skip to content

Commit 620c074

Browse files
committed
Improve logic, fix tests
1 parent cfb3edb commit 620c074

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/Cli/dotnet/commands/RestoringCommand.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RestoringCommand(
2525
userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath;
2626
Task.Run(() => WorkloadManifestUpdater.BackgroundUpdateAdvertisingManifestsAsync(userProfileDir));
2727
SeparateRestoreCommand = GetSeparateRestoreCommand(msbuildArgs, noRestore, msbuildPath);
28-
AdvertiseWorkloadUpdates = advertiseWorkloadUpdates ?? msbuildArgs.All(arg => FlagsToExcludeFromRestore.All(f => !arg.Contains(f, StringComparison.OrdinalIgnoreCase)));
28+
AdvertiseWorkloadUpdates = advertiseWorkloadUpdates ?? msbuildArgs.All(arg => FlagsThatTriggerSilentRestore.All(f => !arg.Contains(f, StringComparison.OrdinalIgnoreCase)));
2929

3030
if (!noRestore)
3131
{
@@ -44,7 +44,7 @@ private static IEnumerable<string> GetCommandArguments(
4444

4545
if (HasArgumentToExcludeFromRestore(arguments))
4646
{
47-
return Prepend("-nologo", Prepend("-verbosity:quiet", arguments));
47+
return Prepend("-nologo", arguments);
4848
}
4949

5050
return Prepend("-restore", arguments);
@@ -84,13 +84,19 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
8484
"TargetFramework"
8585
];
8686

87+
// These arguments should lead to absolutely no output from the restore command
88+
private static readonly string[] FlagsThatTriggerSilentRestore =
89+
[
90+
"getProperty",
91+
"getItem",
92+
"getTargetResult"
93+
];
94+
8795
// These arguments don't by themselves require that restore be run in a separate process,
8896
// but if there is a separate restore process they shouldn't be passed to it
8997
private static readonly string[] FlagsToExcludeFromRestore =
9098
[
91-
"getProperty",
92-
"getItem",
93-
"getTargetResult",
99+
..FlagsThatTriggerSilentRestore,
94100
"t",
95101
"target",
96102
"consoleloggerparameters",
@@ -108,7 +114,7 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
108114
// that we need to compensate for, so we might yield new arguments that should be included in the overall restore call.
109115
private static (string[] newArgumentsToAdd, string[] existingArgumentsToForward) ProcessForwardedArgumentsForSeparateRestore(IEnumerable<string> forwardedArguments)
110116
{
111-
HashSet<string> newArgumentsToAdd = new();
117+
HashSet<string> newArgumentsToAdd = new() { "-nologo", "-verbosity:quiet" };
112118
List<string> existingArgumentsToForward = new();
113119

114120
foreach (var argument in forwardedArguments)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ 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 -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")]
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 -nologo -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")]
6767
[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")]
6868
public void MsbuildInvocationIsCorrectForSeparateRestore(

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 -nologo -verbosity:quiet {ExpectedProperties}");
7777

7878
command.GetArgumentsToMSBuild()
7979
.Should()

0 commit comments

Comments
 (0)