Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 3231295

Browse files
committed
Fixing a bug in the restore option where specifying verbosity through /v was not entirely honored.
Adding tests for implicit restore for all the affected commands. Fixing an issue where the command target was being passed to the restore command during implicit restore. Adding restore params to all commands with implicit restore. Also, implicitly set the restore output to quiet. Adding tests for the no-restore option.
1 parent dd76fec commit 3231295

File tree

14 files changed

+475
-179
lines changed

14 files changed

+475
-179
lines changed

src/dotnet/commands/RestoringCommand.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ public class RestoringCommand : MSBuildForwardingApp
1414

1515
private IEnumerable<string> ArgsToForward { get; }
1616

17+
private IEnumerable<string> ArgsToForwardToRestore
18+
{
19+
get
20+
{
21+
var restoreArguments = ArgsToForward.Where(a =>
22+
!a.StartsWith("/t:") &&
23+
!a.StartsWith("/target:") &&
24+
!a.StartsWith("/ConsoleLoggerParameters:") &&
25+
!a.StartsWith("/clp:"));
26+
27+
if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
28+
{
29+
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
30+
}
31+
32+
return restoreArguments;
33+
}
34+
}
35+
36+
private bool ShouldRunImplicitRestore => !NoRestore;
37+
1738
public RestoringCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
1839
: base(msbuildArgs, msbuildPath)
1940
{
@@ -25,7 +46,7 @@ public override int Execute()
2546
{
2647
if (ShouldRunImplicitRestore)
2748
{
28-
int exitCode = RestoreCommand.Run(ArgsToForward.ToArray());
49+
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray());
2950
if (exitCode != 0)
3051
{
3152
return exitCode;
@@ -34,7 +55,5 @@ public override int Execute()
3455

3556
return base.Execute();
3657
}
37-
38-
private bool ShouldRunImplicitRestore => !NoRestore;
3958
}
4059
}
Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Collections.Generic;
45
using System.Linq;
56
using Microsoft.DotNet.Cli.CommandLine;
67
using Microsoft.DotNet.Tools;
@@ -18,26 +19,42 @@ public static Command Build() =>
1819
.With(name: CommonLocalizableStrings.CmdProjectFile,
1920
description:
2021
"The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."),
21-
CommonOptions.HelpOption(),
22-
Create.Option(
23-
"-o|--output",
24-
LocalizableStrings.OutputOptionDescription,
25-
Accept.ExactlyOneArgument()
26-
.With(name: LocalizableStrings.OutputOptionName)
27-
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
28-
CommonOptions.FrameworkOption(),
29-
CommonOptions.RuntimeOption(),
30-
CommonOptions.ConfigurationOption(),
31-
CommonOptions.VersionSuffixOption(),
32-
Create.Option(
33-
"--no-incremental",
34-
LocalizableStrings.NoIncrementialOptionDescription),
35-
Create.Option(
36-
"--no-dependencies",
37-
LocalizableStrings.NoDependenciesOptionDescription,
38-
Accept.NoArguments()
39-
.ForwardAs("/p:BuildProjectReferences=false")),
40-
CommonOptions.NoRestoreOption(),
41-
CommonOptions.VerbosityOption());
22+
FullBuildOptions
23+
);
24+
25+
private static Option[] FullBuildOptions
26+
{
27+
get
28+
{
29+
var fullBuildOptions = new List<Option>
30+
{
31+
CommonOptions.HelpOption(),
32+
Create.Option(
33+
"-o|--output",
34+
LocalizableStrings.OutputOptionDescription,
35+
Accept.ExactlyOneArgument()
36+
.With(name: LocalizableStrings.OutputOptionName)
37+
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
38+
CommonOptions.FrameworkOption(),
39+
CommonOptions.RuntimeOption(),
40+
CommonOptions.ConfigurationOption(),
41+
CommonOptions.VersionSuffixOption(),
42+
Create.Option(
43+
"--no-incremental",
44+
LocalizableStrings.NoIncrementialOptionDescription),
45+
Create.Option(
46+
"--no-dependencies",
47+
LocalizableStrings.NoDependenciesOptionDescription,
48+
Accept.NoArguments()
49+
.ForwardAs("/p:BuildProjectReferences=false")),
50+
CommonOptions.NoRestoreOption(),
51+
CommonOptions.VerbosityOption()
52+
};
53+
54+
RestoreCommandParser.AddImplicitRestoreOptions(fullBuildOptions);
55+
56+
return fullBuildOptions.ToArray();
57+
}
58+
}
4259
}
4360
}
Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Collections.Generic;
45
using System.Linq;
56
using Microsoft.DotNet.Cli.CommandLine;
67
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;
@@ -14,32 +15,47 @@ public static Command Pack() =>
1415
"pack",
1516
LocalizableStrings.AppFullName,
1617
Accept.ZeroOrMoreArguments(),
17-
CommonOptions.HelpOption(),
18-
Create.Option(
19-
"-o|--output",
20-
LocalizableStrings.CmdOutputDirDescription,
21-
Accept.ExactlyOneArgument()
22-
.With(name: LocalizableStrings.CmdOutputDir)
23-
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
24-
Create.Option(
25-
"--no-build",
26-
LocalizableStrings.CmdNoBuildOptionDescription,
27-
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
28-
Create.Option(
29-
"--include-symbols",
30-
LocalizableStrings.CmdIncludeSymbolsDescription,
31-
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
32-
Create.Option(
33-
"--include-source",
34-
LocalizableStrings.CmdIncludeSourceDescription,
35-
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
36-
CommonOptions.ConfigurationOption(),
37-
CommonOptions.VersionSuffixOption(),
38-
Create.Option(
39-
"-s|--serviceable",
40-
LocalizableStrings.CmdServiceableDescription,
41-
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
42-
CommonOptions.NoRestoreOption(),
43-
CommonOptions.VerbosityOption());
18+
FullPackOptions);
19+
20+
private static Option[] FullPackOptions
21+
{
22+
get
23+
{
24+
var fullPackOptions = new List<Option>
25+
{
26+
CommonOptions.HelpOption(),
27+
Create.Option(
28+
"-o|--output",
29+
LocalizableStrings.CmdOutputDirDescription,
30+
Accept.ExactlyOneArgument()
31+
.With(name: LocalizableStrings.CmdOutputDir)
32+
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
33+
Create.Option(
34+
"--no-build",
35+
LocalizableStrings.CmdNoBuildOptionDescription,
36+
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
37+
Create.Option(
38+
"--include-symbols",
39+
LocalizableStrings.CmdIncludeSymbolsDescription,
40+
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
41+
Create.Option(
42+
"--include-source",
43+
LocalizableStrings.CmdIncludeSourceDescription,
44+
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
45+
CommonOptions.ConfigurationOption(),
46+
CommonOptions.VersionSuffixOption(),
47+
Create.Option(
48+
"-s|--serviceable",
49+
LocalizableStrings.CmdServiceableDescription,
50+
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
51+
CommonOptions.NoRestoreOption(),
52+
CommonOptions.VerbosityOption()
53+
};
54+
55+
RestoreCommandParser.AddImplicitRestoreOptions(fullPackOptions);
56+
57+
return fullPackOptions.ToArray();
58+
}
59+
}
4460
}
4561
}
Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Collections.Generic;
45
using System.Linq;
56
using Microsoft.DotNet.Cli.CommandLine;
67
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;
@@ -14,34 +15,49 @@ public static Command Publish() =>
1415
"publish",
1516
LocalizableStrings.AppDescription,
1617
Accept.ZeroOrMoreArguments(),
17-
CommonOptions.HelpOption(),
18-
Create.Option(
19-
"-o|--output",
20-
LocalizableStrings.OutputOptionDescription,
21-
Accept.ExactlyOneArgument()
22-
.With(name: LocalizableStrings.OutputOption)
23-
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
24-
CommonOptions.FrameworkOption(),
25-
CommonOptions.RuntimeOption(),
26-
CommonOptions.ConfigurationOption(),
27-
CommonOptions.VersionSuffixOption(),
28-
Create.Option(
29-
"--manifest",
30-
LocalizableStrings.ManifestOptionDescription,
31-
Accept.OneOrMoreArguments()
32-
.With(name: LocalizableStrings.ManifestOption)
33-
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
34-
Create.Option(
35-
"--self-contained",
36-
LocalizableStrings.SelfContainedOptionDescription,
37-
Accept.ZeroOrOneArgument()
38-
.WithSuggestionsFrom("true", "false")
39-
.ForwardAsSingle(o =>
40-
{
41-
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
42-
return $"/p:SelfContained={value}";
43-
})),
44-
CommonOptions.NoRestoreOption(),
45-
CommonOptions.VerbosityOption());
18+
FullPublishOptions);
19+
20+
private static Option[] FullPublishOptions
21+
{
22+
get
23+
{
24+
var fullPublishOptions = new List<Option>
25+
{
26+
CommonOptions.HelpOption(),
27+
Create.Option(
28+
"-o|--output",
29+
LocalizableStrings.OutputOptionDescription,
30+
Accept.ExactlyOneArgument()
31+
.With(name: LocalizableStrings.OutputOption)
32+
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
33+
CommonOptions.FrameworkOption(),
34+
CommonOptions.RuntimeOption(),
35+
CommonOptions.ConfigurationOption(),
36+
CommonOptions.VersionSuffixOption(),
37+
Create.Option(
38+
"--manifest",
39+
LocalizableStrings.ManifestOptionDescription,
40+
Accept.OneOrMoreArguments()
41+
.With(name: LocalizableStrings.ManifestOption)
42+
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
43+
Create.Option(
44+
"--self-contained",
45+
LocalizableStrings.SelfContainedOptionDescription,
46+
Accept.ZeroOrOneArgument()
47+
.WithSuggestionsFrom("true", "false")
48+
.ForwardAsSingle(o =>
49+
{
50+
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
51+
return $"/p:SelfContained={value}";
52+
})),
53+
CommonOptions.NoRestoreOption(),
54+
CommonOptions.VerbosityOption()
55+
};
56+
57+
RestoreCommandParser.AddImplicitRestoreOptions(fullPublishOptions);
58+
59+
return fullPublishOptions.ToArray();
60+
}
61+
}
4662
}
4763
}

src/dotnet/commands/dotnet-restore/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public static RestoreCommand FromArgs(string[] args, string msbuildPath = null)
3737
"/t:Restore"
3838
};
3939

40-
if (!parsedRestore.HasOption("verbosity"))
40+
if (!HasVerbosityOption(parsedRestore))
4141
{
4242
msbuildArgs.Add("/ConsoleLoggerParameters:Verbosity=Minimal");
4343
}
4444

4545
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
4646

4747
msbuildArgs.AddRange(parsedRestore.Arguments);
48-
48+
4949
return new RestoreCommand(msbuildArgs, msbuildPath);
5050
}
5151

@@ -65,5 +65,12 @@ public static int Run(string[] args)
6565

6666
return cmd.Execute();
6767
}
68+
69+
private static bool HasVerbosityOption(AppliedOption parsedRestore)
70+
{
71+
return parsedRestore.HasOption("verbosity") ||
72+
parsedRestore.Arguments.Any(a => a.Contains("/v:")) ||
73+
parsedRestore.Arguments.Any(a => a.Contains("/verbosity:"));
74+
}
6875
}
6976
}

0 commit comments

Comments
 (0)