diff --git a/src/dotnet/CommonLocalizableStrings.resx b/src/dotnet/CommonLocalizableStrings.resx
index 708b0daf3..a2f5c3270 100644
--- a/src/dotnet/CommonLocalizableStrings.resx
+++ b/src/dotnet/CommonLocalizableStrings.resx
@@ -520,4 +520,7 @@
Show help information.
+
+ Does not do an implicit restore when executing the command.
+
\ No newline at end of file
diff --git a/src/dotnet/commands/CommandWithRestoreOptions.cs b/src/dotnet/commands/CommandWithRestoreOptions.cs
new file mode 100644
index 000000000..aaf9748d5
--- /dev/null
+++ b/src/dotnet/commands/CommandWithRestoreOptions.cs
@@ -0,0 +1,39 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.DotNet.Cli;
+using Microsoft.DotNet.Cli.CommandLine;
+using Microsoft.DotNet.Tools.MSBuild;
+using Microsoft.DotNet.Tools.Restore;
+
+namespace Microsoft.DotNet.Tools
+{
+ public static class CreateWithRestoreOptions
+ {
+ public static Command Command(
+ string name,
+ string help,
+ ArgumentsRule arguments,
+ params Option[] options)
+ {
+ return Create.Command(name, help, arguments, RestoreCommandParser.AddImplicitRestoreOptions(options));
+ }
+
+ public static Command Command(
+ string name,
+ string help,
+ ArgumentsRule arguments,
+ bool treatUnmatchedTokensAsErrors,
+ params Option[] options)
+ {
+ return Create.Command(
+ name,
+ help,
+ arguments,
+ treatUnmatchedTokensAsErrors,
+ RestoreCommandParser.AddImplicitRestoreOptions(options));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/dotnet/commands/RestoringCommand.cs b/src/dotnet/commands/RestoringCommand.cs
index 89e4afa5b..67c114577 100644
--- a/src/dotnet/commands/RestoringCommand.cs
+++ b/src/dotnet/commands/RestoringCommand.cs
@@ -14,23 +14,20 @@ namespace Microsoft.DotNet.Tools
private IEnumerable ArgsToForward { get; }
- private IEnumerable ArgsToForwardToRestore
+ private IEnumerable ArgsToForwardToRestore()
{
- get
+ var restoreArguments = ArgsToForward.Where(a =>
+ !a.StartsWith("/t:") &&
+ !a.StartsWith("/target:") &&
+ !a.StartsWith("/ConsoleLoggerParameters:") &&
+ !a.StartsWith("/clp:"));
+
+ if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
{
- var restoreArguments = ArgsToForward.Where(a =>
- !a.StartsWith("/t:") &&
- !a.StartsWith("/target:") &&
- !a.StartsWith("/ConsoleLoggerParameters:") &&
- !a.StartsWith("/clp:"));
-
- if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
- {
- restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
- }
-
- return restoreArguments;
+ restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
}
+
+ return restoreArguments;
}
private bool ShouldRunImplicitRestore => !NoRestore;
@@ -46,7 +43,7 @@ namespace Microsoft.DotNet.Tools
{
if (ShouldRunImplicitRestore)
{
- int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray());
+ int exitCode = RestoreCommand.Run(ArgsToForwardToRestore().ToArray());
if (exitCode != 0)
{
return exitCode;
diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs
index 60b1a4b1c..76da0258e 100644
--- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs
+++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs
@@ -12,49 +12,33 @@ namespace Microsoft.DotNet.Cli
internal static class BuildCommandParser
{
public static Command Build() =>
- Create.Command(
+ CreateWithRestoreOptions.Command(
"build",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments()
.With(name: CommonLocalizableStrings.CmdProjectFile,
description:
"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."),
- FullBuildOptions
- );
-
- private static Option[] FullBuildOptions
- {
- get
- {
- var fullBuildOptions = new List