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) =>
|
||||
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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using Microsoft.DotNet.Tools;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Tools.Restore;
|
||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Build
|
||||
{
|
||||
public class BuildCommand : MSBuildForwardingApp
|
||||
public class BuildCommand : RestoringCommand
|
||||
{
|
||||
public BuildCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||
: base(msbuildArgs, msbuildPath)
|
||||
public BuildCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||
: base(msbuildArgs, noRestore, msbuildPath)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -44,7 +47,9 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
|
||||
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)
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace Microsoft.DotNet.Cli
|
|||
LocalizableStrings.NoDependenciesOptionDescription,
|
||||
Accept.NoArguments()
|
||||
.ForwardAs("/p:BuildProjectReferences=false")),
|
||||
CommonOptions.NoRestoreOption(),
|
||||
CommonOptions.VerbosityOption());
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
|
|||
return ret;
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
public virtual int Execute()
|
||||
{
|
||||
return GetProcessStartInfo().Execute();
|
||||
}
|
||||
|
|
|
@ -5,16 +5,17 @@ using System.Collections.Generic;
|
|||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using Microsoft.DotNet.Tools;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using System.Diagnostics;
|
||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Pack
|
||||
{
|
||||
public class PackCommand : MSBuildForwardingApp
|
||||
public class PackCommand : RestoringCommand
|
||||
{
|
||||
public PackCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||
: base(msbuildArgs, msbuildPath)
|
||||
public PackCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||
: base(msbuildArgs, noRestore, msbuildPath)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -30,14 +31,16 @@ namespace Microsoft.DotNet.Tools.Pack
|
|||
|
||||
var msbuildArgs = new List<string>()
|
||||
{
|
||||
"/t:pack"
|
||||
"/t:pack"
|
||||
};
|
||||
|
||||
msbuildArgs.AddRange(parsedPack.OptionValuesToBeForwarded());
|
||||
|
||||
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)
|
||||
|
|
|
@ -39,6 +39,7 @@ namespace Microsoft.DotNet.Cli
|
|||
"-s|--serviceable",
|
||||
LocalizableStrings.CmdServiceableDescription,
|
||||
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
|
||||
CommonOptions.NoRestoreOption(),
|
||||
CommonOptions.VerbosityOption());
|
||||
}
|
||||
}
|
|
@ -5,15 +5,16 @@ using System.Collections.Generic;
|
|||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Publish
|
||||
{
|
||||
public class PublishCommand : MSBuildForwardingApp
|
||||
public class PublishCommand : RestoringCommand
|
||||
{
|
||||
private PublishCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||
: base(msbuildArgs, msbuildPath)
|
||||
private PublishCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||
: base(msbuildArgs, noRestore, msbuildPath)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,9 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
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)
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace Microsoft.DotNet.Cli
|
|||
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
|
||||
return $"/p:SelfContained={value}";
|
||||
})),
|
||||
CommonOptions.NoRestoreOption(),
|
||||
CommonOptions.VerbosityOption());
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using Microsoft.Build.Evaluation;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using Microsoft.DotNet.Tools.Run.LaunchSettings;
|
||||
|
||||
|
@ -19,6 +20,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
public bool NoBuild { get; private set; }
|
||||
public string Project { get; private set; }
|
||||
public IReadOnlyCollection<string> Args { get; private set; }
|
||||
public bool NoRestore { get; private set; }
|
||||
|
||||
private List<string> _args;
|
||||
private bool ShouldBuild => !NoBuild;
|
||||
|
@ -55,6 +57,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
string project,
|
||||
string launchProfile,
|
||||
bool noLaunchProfile,
|
||||
bool noRestore,
|
||||
IReadOnlyCollection<string> args)
|
||||
{
|
||||
Configuration = configuration;
|
||||
|
@ -64,6 +67,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
LaunchProfile = launchProfile;
|
||||
NoLaunchProfile = noLaunchProfile;
|
||||
Args = args;
|
||||
NoRestore = noRestore;
|
||||
}
|
||||
|
||||
public RunCommand MakeNewWithReplaced(string configuration = null,
|
||||
|
@ -72,6 +76,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
string project = null,
|
||||
string launchProfile = null,
|
||||
bool? noLaunchProfile = null,
|
||||
bool? noRestore = null,
|
||||
IReadOnlyCollection<string> args = null)
|
||||
{
|
||||
return new RunCommand(
|
||||
|
@ -81,6 +86,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
project ?? this.Project,
|
||||
launchProfile ?? this.LaunchProfile,
|
||||
noLaunchProfile ?? this.NoLaunchProfile,
|
||||
noRestore ?? this.NoRestore,
|
||||
args ?? this.Args
|
||||
);
|
||||
}
|
||||
|
@ -142,8 +148,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
buildArgs.Add($"/p:TargetFramework={Framework}");
|
||||
}
|
||||
|
||||
var buildResult = new MSBuildForwardingApp(buildArgs).Execute();
|
||||
|
||||
var buildResult = new RestoringCommand(buildArgs, NoRestore).Execute();
|
||||
if (buildResult != 0)
|
||||
{
|
||||
Reporter.Error.WriteLine();
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Microsoft.DotNet.Cli
|
|||
project: o.SingleArgumentOrDefault("--project"),
|
||||
launchProfile: o.SingleArgumentOrDefault("--launch-profile"),
|
||||
noLaunchProfile: o.HasOption("--no-launch-profile"),
|
||||
noRestore: o.HasOption("--no-restore"),
|
||||
args: o.Arguments
|
||||
)),
|
||||
options: new[]
|
||||
|
@ -45,7 +46,8 @@ namespace Microsoft.DotNet.Cli
|
|||
Create.Option(
|
||||
"--no-build",
|
||||
LocalizableStrings.CommandOptionNoBuildDescription,
|
||||
Accept.NoArguments())
|
||||
Accept.NoArguments()),
|
||||
CommonOptions.NoRestoreOption(),
|
||||
});
|
||||
}
|
||||
}
|
|
@ -14,10 +14,10 @@ using Parser = Microsoft.DotNet.Cli.Parser;
|
|||
|
||||
namespace Microsoft.DotNet.Tools.Test
|
||||
{
|
||||
public class TestCommand : MSBuildForwardingApp
|
||||
public class TestCommand : RestoringCommand
|
||||
{
|
||||
public TestCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||
: base(msbuildArgs, msbuildPath)
|
||||
public TestCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
|
||||
: 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)
|
||||
|
|
|
@ -81,6 +81,7 @@ namespace Microsoft.DotNet.Cli
|
|||
Accept.OneOrMoreArguments()
|
||||
.With(name: LocalizableStrings.cmdCollectFriendlyName)
|
||||
.ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")),
|
||||
CommonOptions.NoRestoreOption(),
|
||||
CommonOptions.VerbosityOption());
|
||||
|
||||
private static string GetSemiColonEsacpedstring(string arg)
|
||||
|
|
Loading…
Reference in a new issue