Implicit restore for build, pack, publish, run and test.
This commit is contained in:
parent
a3d6c2a551
commit
dd76fec564
13 changed files with 91 additions and 21 deletions
|
@ -65,5 +65,11 @@ namespace Microsoft.DotNet.Cli
|
||||||
|
|
||||||
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) =>
|
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) =>
|
||||||
rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
|
rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
|
||||||
|
|
||||||
|
public static Option NoRestoreOption() =>
|
||||||
|
Create.Option(
|
||||||
|
"--no-restore",
|
||||||
|
CommonLocalizableStrings.NoRestoreDescription,
|
||||||
|
Accept.NoArguments());
|
||||||
}
|
}
|
||||||
}
|
}
|
40
src/dotnet/commands/RestoringCommand.cs
Normal file
40
src/dotnet/commands/RestoringCommand.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// 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.Tools.MSBuild;
|
||||||
|
using Microsoft.DotNet.Tools.Restore;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Tools
|
||||||
|
{
|
||||||
|
public class RestoringCommand : MSBuildForwardingApp
|
||||||
|
{
|
||||||
|
private bool NoRestore { get; }
|
||||||
|
|
||||||
|
private IEnumerable<string> ArgsToForward { get; }
|
||||||
|
|
||||||
|
public RestoringCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||||
|
: base(msbuildArgs, msbuildPath)
|
||||||
|
{
|
||||||
|
NoRestore = noRestore;
|
||||||
|
ArgsToForward = msbuildArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Execute()
|
||||||
|
{
|
||||||
|
if (ShouldRunImplicitRestore)
|
||||||
|
{
|
||||||
|
int exitCode = RestoreCommand.Run(ArgsToForward.ToArray());
|
||||||
|
if (exitCode != 0)
|
||||||
|
{
|
||||||
|
return exitCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ShouldRunImplicitRestore => !NoRestore;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,18 +2,21 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
|
using Microsoft.DotNet.Tools;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
|
using Microsoft.DotNet.Tools.Restore;
|
||||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Build
|
namespace Microsoft.DotNet.Tools.Build
|
||||||
{
|
{
|
||||||
public class BuildCommand : MSBuildForwardingApp
|
public class BuildCommand : RestoringCommand
|
||||||
{
|
{
|
||||||
public BuildCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
public BuildCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||||
: base(msbuildArgs, msbuildPath)
|
: base(msbuildArgs, noRestore, msbuildPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +47,9 @@ namespace Microsoft.DotNet.Tools.Build
|
||||||
|
|
||||||
msbuildArgs.Add($"/clp:Summary");
|
msbuildArgs.Add($"/clp:Summary");
|
||||||
|
|
||||||
return new BuildCommand(msbuildArgs, msbuildPath);
|
bool noRestore = appliedBuildOptions.HasOption("--no-restore");
|
||||||
|
|
||||||
|
return new BuildCommand(msbuildArgs, noRestore, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
LocalizableStrings.NoDependenciesOptionDescription,
|
LocalizableStrings.NoDependenciesOptionDescription,
|
||||||
Accept.NoArguments()
|
Accept.NoArguments()
|
||||||
.ForwardAs("/p:BuildProjectReferences=false")),
|
.ForwardAs("/p:BuildProjectReferences=false")),
|
||||||
|
CommonOptions.NoRestoreOption(),
|
||||||
CommonOptions.VerbosityOption());
|
CommonOptions.VerbosityOption());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -58,7 +58,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Execute()
|
public virtual int Execute()
|
||||||
{
|
{
|
||||||
return GetProcessStartInfo().Execute();
|
return GetProcessStartInfo().Execute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,17 @@ using System.Collections.Generic;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
|
using Microsoft.DotNet.Tools;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Pack
|
namespace Microsoft.DotNet.Tools.Pack
|
||||||
{
|
{
|
||||||
public class PackCommand : MSBuildForwardingApp
|
public class PackCommand : RestoringCommand
|
||||||
{
|
{
|
||||||
public PackCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
public PackCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||||
: base(msbuildArgs, msbuildPath)
|
: base(msbuildArgs, noRestore, msbuildPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,14 +31,16 @@ namespace Microsoft.DotNet.Tools.Pack
|
||||||
|
|
||||||
var msbuildArgs = new List<string>()
|
var msbuildArgs = new List<string>()
|
||||||
{
|
{
|
||||||
"/t:pack"
|
"/t:pack"
|
||||||
};
|
};
|
||||||
|
|
||||||
msbuildArgs.AddRange(parsedPack.OptionValuesToBeForwarded());
|
msbuildArgs.AddRange(parsedPack.OptionValuesToBeForwarded());
|
||||||
|
|
||||||
msbuildArgs.AddRange(parsedPack.Arguments);
|
msbuildArgs.AddRange(parsedPack.Arguments);
|
||||||
|
|
||||||
return new PackCommand(msbuildArgs, msbuildPath);
|
bool noRestore = parsedPack.HasOption("--no-restore");
|
||||||
|
|
||||||
|
return new PackCommand(msbuildArgs, noRestore, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
"-s|--serviceable",
|
"-s|--serviceable",
|
||||||
LocalizableStrings.CmdServiceableDescription,
|
LocalizableStrings.CmdServiceableDescription,
|
||||||
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
|
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
|
||||||
|
CommonOptions.NoRestoreOption(),
|
||||||
CommonOptions.VerbosityOption());
|
CommonOptions.VerbosityOption());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,15 +5,16 @@ using System.Collections.Generic;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using Microsoft.DotNet.Tools;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish
|
namespace Microsoft.DotNet.Tools.Publish
|
||||||
{
|
{
|
||||||
public class PublishCommand : MSBuildForwardingApp
|
public class PublishCommand : RestoringCommand
|
||||||
{
|
{
|
||||||
private PublishCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
private PublishCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||||
: base(msbuildArgs, msbuildPath)
|
: base(msbuildArgs, noRestore, msbuildPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +38,9 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
|
|
||||||
msbuildArgs.AddRange(appliedPublishOption.Arguments);
|
msbuildArgs.AddRange(appliedPublishOption.Arguments);
|
||||||
|
|
||||||
return new PublishCommand(msbuildArgs, msbuildPath);
|
bool noRestore = appliedPublishOption.HasOption("--no-restore");
|
||||||
|
|
||||||
|
return new PublishCommand(msbuildArgs, noRestore, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
|
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
|
||||||
return $"/p:SelfContained={value}";
|
return $"/p:SelfContained={value}";
|
||||||
})),
|
})),
|
||||||
|
CommonOptions.NoRestoreOption(),
|
||||||
CommonOptions.VerbosityOption());
|
CommonOptions.VerbosityOption());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Build.Evaluation;
|
using Microsoft.Build.Evaluation;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using Microsoft.DotNet.Tools;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
using Microsoft.DotNet.Tools.Run.LaunchSettings;
|
using Microsoft.DotNet.Tools.Run.LaunchSettings;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
public bool NoBuild { get; private set; }
|
public bool NoBuild { get; private set; }
|
||||||
public string Project { get; private set; }
|
public string Project { get; private set; }
|
||||||
public IReadOnlyCollection<string> Args { get; private set; }
|
public IReadOnlyCollection<string> Args { get; private set; }
|
||||||
|
public bool NoRestore { get; private set; }
|
||||||
|
|
||||||
private List<string> _args;
|
private List<string> _args;
|
||||||
private bool ShouldBuild => !NoBuild;
|
private bool ShouldBuild => !NoBuild;
|
||||||
|
@ -55,6 +57,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
string project,
|
string project,
|
||||||
string launchProfile,
|
string launchProfile,
|
||||||
bool noLaunchProfile,
|
bool noLaunchProfile,
|
||||||
|
bool noRestore,
|
||||||
IReadOnlyCollection<string> args)
|
IReadOnlyCollection<string> args)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
|
@ -64,6 +67,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
LaunchProfile = launchProfile;
|
LaunchProfile = launchProfile;
|
||||||
NoLaunchProfile = noLaunchProfile;
|
NoLaunchProfile = noLaunchProfile;
|
||||||
Args = args;
|
Args = args;
|
||||||
|
NoRestore = noRestore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunCommand MakeNewWithReplaced(string configuration = null,
|
public RunCommand MakeNewWithReplaced(string configuration = null,
|
||||||
|
@ -72,6 +76,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
string project = null,
|
string project = null,
|
||||||
string launchProfile = null,
|
string launchProfile = null,
|
||||||
bool? noLaunchProfile = null,
|
bool? noLaunchProfile = null,
|
||||||
|
bool? noRestore = null,
|
||||||
IReadOnlyCollection<string> args = null)
|
IReadOnlyCollection<string> args = null)
|
||||||
{
|
{
|
||||||
return new RunCommand(
|
return new RunCommand(
|
||||||
|
@ -81,6 +86,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
project ?? this.Project,
|
project ?? this.Project,
|
||||||
launchProfile ?? this.LaunchProfile,
|
launchProfile ?? this.LaunchProfile,
|
||||||
noLaunchProfile ?? this.NoLaunchProfile,
|
noLaunchProfile ?? this.NoLaunchProfile,
|
||||||
|
noRestore ?? this.NoRestore,
|
||||||
args ?? this.Args
|
args ?? this.Args
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -142,8 +148,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
buildArgs.Add($"/p:TargetFramework={Framework}");
|
buildArgs.Add($"/p:TargetFramework={Framework}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildResult = new MSBuildForwardingApp(buildArgs).Execute();
|
var buildResult = new RestoringCommand(buildArgs, NoRestore).Execute();
|
||||||
|
|
||||||
if (buildResult != 0)
|
if (buildResult != 0)
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine();
|
Reporter.Error.WriteLine();
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
project: o.SingleArgumentOrDefault("--project"),
|
project: o.SingleArgumentOrDefault("--project"),
|
||||||
launchProfile: o.SingleArgumentOrDefault("--launch-profile"),
|
launchProfile: o.SingleArgumentOrDefault("--launch-profile"),
|
||||||
noLaunchProfile: o.HasOption("--no-launch-profile"),
|
noLaunchProfile: o.HasOption("--no-launch-profile"),
|
||||||
|
noRestore: o.HasOption("--no-restore"),
|
||||||
args: o.Arguments
|
args: o.Arguments
|
||||||
)),
|
)),
|
||||||
options: new[]
|
options: new[]
|
||||||
|
@ -45,7 +46,8 @@ namespace Microsoft.DotNet.Cli
|
||||||
Create.Option(
|
Create.Option(
|
||||||
"--no-build",
|
"--no-build",
|
||||||
LocalizableStrings.CommandOptionNoBuildDescription,
|
LocalizableStrings.CommandOptionNoBuildDescription,
|
||||||
Accept.NoArguments())
|
Accept.NoArguments()),
|
||||||
|
CommonOptions.NoRestoreOption(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,10 +14,10 @@ using Parser = Microsoft.DotNet.Cli.Parser;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Test
|
namespace Microsoft.DotNet.Tools.Test
|
||||||
{
|
{
|
||||||
public class TestCommand : MSBuildForwardingApp
|
public class TestCommand : RestoringCommand
|
||||||
{
|
{
|
||||||
public TestCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
public TestCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||||
: base(msbuildArgs, msbuildPath)
|
: base(msbuildArgs, noRestore, msbuildPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,9 @@ namespace Microsoft.DotNet.Tools.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TestCommand(msbuildArgs, msbuildPath);
|
bool noRestore = parsedTest.HasOption("--no-restore");
|
||||||
|
|
||||||
|
return new TestCommand(msbuildArgs, noRestore, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
|
|
@ -81,6 +81,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
Accept.OneOrMoreArguments()
|
Accept.OneOrMoreArguments()
|
||||||
.With(name: LocalizableStrings.cmdCollectFriendlyName)
|
.With(name: LocalizableStrings.cmdCollectFriendlyName)
|
||||||
.ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")),
|
.ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")),
|
||||||
|
CommonOptions.NoRestoreOption(),
|
||||||
CommonOptions.VerbosityOption());
|
CommonOptions.VerbosityOption());
|
||||||
|
|
||||||
private static string GetSemiColonEsacpedstring(string arg)
|
private static string GetSemiColonEsacpedstring(string arg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue