Merge pull request #6762 from livarcocc/implicit_restore

Add Implicit restore to run/build/publish/pack/test
This commit is contained in:
Livar 2017-06-08 09:21:27 -07:00 committed by GitHub
commit 607d776782
22 changed files with 392 additions and 58 deletions

View file

@ -520,4 +520,7 @@
<data name="ShowHelpDescription" xml:space="preserve">
<value>Show help information.</value>
</data>
<data name="NoRestoreDescription" xml:space="preserve">
<value>Does not do an implicit restore when executing the command.</value>
</data>
</root>

View file

@ -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());
}
}

View file

@ -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));
}
}
}

View file

@ -0,0 +1,56 @@
// 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; }
private IEnumerable<string> ArgsToForwardToRestore()
{
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;
}
private bool ShouldRunImplicitRestore => !NoRestore;
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(ArgsToForwardToRestore().ToArray());
if (exitCode != 0)
{
return exitCode;
}
}
return base.Execute();
}
}
}

View file

@ -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)

View file

@ -1,6 +1,7 @@
// 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.CommandLine;
using Microsoft.DotNet.Tools;
@ -11,7 +12,7 @@ namespace Microsoft.DotNet.Cli
internal static class BuildCommandParser
{
public static Command Build() =>
Create.Command(
CreateWithRestoreOptions.Command(
"build",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments()
@ -37,6 +38,7 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.NoDependenciesOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:BuildProjectReferences=false")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
}
}

View file

@ -58,7 +58,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
return ret;
}
public int Execute()
public virtual int Execute()
{
return GetProcessStartInfo().Execute();
}

View file

@ -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)

View file

@ -1,8 +1,10 @@
// 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.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;
namespace Microsoft.DotNet.Cli
@ -10,7 +12,7 @@ namespace Microsoft.DotNet.Cli
internal static class PackCommandParser
{
public static Command Pack() =>
Create.Command(
CreateWithRestoreOptions.Command(
"pack",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(),
@ -39,6 +41,7 @@ namespace Microsoft.DotNet.Cli
"-s|--serviceable",
LocalizableStrings.CmdServiceableDescription,
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
}
}

View file

@ -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)

View file

@ -1,8 +1,10 @@
// 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.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;
namespace Microsoft.DotNet.Cli
@ -10,7 +12,7 @@ namespace Microsoft.DotNet.Cli
internal static class PublishCommandParser
{
public static Command Publish() =>
Create.Command(
CreateWithRestoreOptions.Command(
"publish",
LocalizableStrings.AppDescription,
Accept.ZeroOrMoreArguments(),
@ -41,6 +43,7 @@ namespace Microsoft.DotNet.Cli
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
return $"/p:SelfContained={value}";
})),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
}
}

View file

@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Tools.Restore
"/t:Restore"
};
if (!parsedRestore.HasOption("verbosity"))
if (!HasVerbosityOption(parsedRestore))
{
msbuildArgs.Add("/ConsoleLoggerParameters:Verbosity=Minimal");
}
@ -45,7 +45,7 @@ namespace Microsoft.DotNet.Tools.Restore
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
msbuildArgs.AddRange(parsedRestore.Arguments);
return new RestoreCommand(msbuildArgs, msbuildPath);
}
@ -65,5 +65,12 @@ namespace Microsoft.DotNet.Tools.Restore
return cmd.Execute();
}
private static bool HasVerbosityOption(AppliedOption parsedRestore)
{
return parsedRestore.HasOption("verbosity") ||
parsedRestore.Arguments.Any(a => a.Contains("/v:")) ||
parsedRestore.Arguments.Any(a => a.Contains("/verbosity:"));
}
}
}

View file

@ -1,6 +1,7 @@
// 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.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Restore.LocalizableStrings;
@ -14,15 +15,41 @@ namespace Microsoft.DotNet.Cli
"restore",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(),
CommonOptions.HelpOption(),
FullRestoreOptions());
private static Option[] FullRestoreOptions()
{
var fullRestoreOptions = AddImplicitRestoreOptions(new Option[] { CommonOptions.HelpOption() }, true, true);
return fullRestoreOptions.Concat(new Option[] { CommonOptions.VerbosityOption() }).ToArray();
}
public static Option[] AddImplicitRestoreOptions(
IEnumerable<Option> commandOptions)
{
return AddImplicitRestoreOptions(commandOptions, false, false).ToArray();
}
private static IEnumerable<Option> AddImplicitRestoreOptions(
IEnumerable<Option> commandOptions,
bool showHelp,
bool useShortOptions)
{
return commandOptions.Concat(ImplicitRestoreOptions(showHelp, useShortOptions)
.Where(o => !commandOptions.Any(c => c.Name == o.Name)));
}
private static Option[] ImplicitRestoreOptions(bool showHelp = false, bool useShortOptions = false)
{
return new Option[] {
Create.Option(
"-s|--source",
LocalizableStrings.CmdSourceOptionDescription,
useShortOptions ? "-s|--source" : "--source",
showHelp ? LocalizableStrings.CmdSourceOptionDescription : string.Empty,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.CmdSourceOption)
.ForwardAsSingle(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")),
Create.Option(
"-r|--runtime",
useShortOptions ? "-r|--runtime" : "--runtime" ,
LocalizableStrings.CmdRuntimeOptionDescription,
Accept.OneOrMoreArguments()
.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile())
@ -30,29 +57,29 @@ namespace Microsoft.DotNet.Cli
.ForwardAsSingle(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")),
Create.Option(
"--packages",
LocalizableStrings.CmdPackagesOptionDescription,
showHelp ? LocalizableStrings.CmdPackagesOptionDescription : string.Empty,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPackagesOption)
.ForwardAsSingle(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")),
Create.Option(
"--disable-parallel",
LocalizableStrings.CmdDisableParallelOptionDescription,
showHelp ? LocalizableStrings.CmdDisableParallelOptionDescription : string.Empty,
Accept.NoArguments()
.ForwardAs("/p:RestoreDisableParallel=true")),
Create.Option(
"--configfile",
LocalizableStrings.CmdConfigFileOptionDescription,
showHelp ? LocalizableStrings.CmdConfigFileOptionDescription : string.Empty,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdConfigFileOption)
.ForwardAsSingle(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")),
Create.Option(
"--no-cache",
LocalizableStrings.CmdNoCacheOptionDescription,
showHelp ? LocalizableStrings.CmdNoCacheOptionDescription : string.Empty,
Accept.NoArguments()
.ForwardAs("/p:RestoreNoCache=true")),
Create.Option(
"--ignore-failed-sources",
LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription,
showHelp ? LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription : string.Empty,
Accept.NoArguments()
.ForwardAs("/p:RestoreIgnoreFailedSources=true")),
Create.Option(
@ -61,10 +88,11 @@ namespace Microsoft.DotNet.Cli
Accept.NoArguments()
.ForwardAs("/p:RestoreRecursive=false")),
Create.Option(
"-f|--force",
useShortOptions ? "-f|--force" : "--force",
LocalizableStrings.CmdForceRestoreOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:RestoreForce=true")),
CommonOptions.VerbosityOption());
.ForwardAs("/p:RestoreForce=true"))
};
}
}
}

View file

@ -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,8 @@ 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; }
public IEnumerable<string> RestoreArgs { get; private set; }
private List<string> _args;
private bool ShouldBuild => !NoBuild;
@ -55,6 +58,8 @@ namespace Microsoft.DotNet.Tools.Run
string project,
string launchProfile,
bool noLaunchProfile,
bool noRestore,
IEnumerable<string> restoreArgs,
IReadOnlyCollection<string> args)
{
Configuration = configuration;
@ -64,6 +69,8 @@ namespace Microsoft.DotNet.Tools.Run
LaunchProfile = launchProfile;
NoLaunchProfile = noLaunchProfile;
Args = args;
RestoreArgs = restoreArgs;
NoRestore = noRestore;
}
public RunCommand MakeNewWithReplaced(string configuration = null,
@ -72,6 +79,8 @@ namespace Microsoft.DotNet.Tools.Run
string project = null,
string launchProfile = null,
bool? noLaunchProfile = null,
bool? noRestore = null,
IEnumerable<string> restoreArgs = null,
IReadOnlyCollection<string> args = null)
{
return new RunCommand(
@ -81,6 +90,8 @@ namespace Microsoft.DotNet.Tools.Run
project ?? this.Project,
launchProfile ?? this.LaunchProfile,
noLaunchProfile ?? this.NoLaunchProfile,
noRestore ?? this.NoRestore,
restoreArgs ?? this.RestoreArgs,
args ?? this.Args
);
}
@ -132,18 +143,9 @@ namespace Microsoft.DotNet.Tools.Run
buildArgs.Add("/nologo");
buildArgs.Add("/verbosity:quiet");
if (!string.IsNullOrWhiteSpace(Configuration))
{
buildArgs.Add($"/p:Configuration={Configuration}");
}
if (!string.IsNullOrWhiteSpace(Framework))
{
buildArgs.Add($"/p:TargetFramework={Framework}");
}
var buildResult = new MSBuildForwardingApp(buildArgs).Execute();
buildArgs.AddRange(RestoreArgs);
var buildResult = new RestoringCommand(buildArgs, NoRestore).Execute();
if (buildResult != 0)
{
Reporter.Error.WriteLine();

View file

@ -1,7 +1,10 @@
// 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.CommandLine;
using Microsoft.DotNet.Tools;
using Microsoft.DotNet.Tools.Run;
using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings;
@ -10,7 +13,7 @@ namespace Microsoft.DotNet.Cli
internal static class RunCommandParser
{
public static Command Run() =>
Create.Command(
CreateWithRestoreOptions.Command(
"run",
LocalizableStrings.AppFullName,
treatUnmatchedTokensAsErrors: false,
@ -23,6 +26,8 @@ namespace Microsoft.DotNet.Cli
project: o.SingleArgumentOrDefault("--project"),
launchProfile: o.SingleArgumentOrDefault("--launch-profile"),
noLaunchProfile: o.HasOption("--no-launch-profile"),
noRestore: o.HasOption("--no-restore"),
restoreArgs: o.OptionValuesToBeForwarded(),
args: o.Arguments
)),
options: new[]
@ -45,7 +50,8 @@ namespace Microsoft.DotNet.Cli
Create.Option(
"--no-build",
LocalizableStrings.CommandOptionNoBuildDescription,
Accept.NoArguments())
Accept.NoArguments()),
CommonOptions.NoRestoreOption()
});
}
}

View file

@ -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)

View file

@ -1,6 +1,10 @@
// 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.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings;
namespace Microsoft.DotNet.Cli
@ -44,10 +48,10 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.CmdLoggerDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdLoggerOption)
.ForwardAsSingle(o =>
.ForwardAsSingle(o =>
{
var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments));
var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments));
return $"/p:VSTestLogger={loggersString}";
})),
CommonOptions.ConfigurationOption(),
@ -81,6 +85,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)

View file

@ -38,6 +38,35 @@ namespace Microsoft.DotNet.Cli.Build.Tests
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenBuilding()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance(testAppName)
.WithSourceFiles();
new BuildCommand()
.WithWorkingDirectory(testInstance.Root)
.Execute()
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenBuildingWithTheNoRestoreOption()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance(testAppName)
.WithSourceFiles();
new BuildCommand()
.WithWorkingDirectory(testInstance.Root)
.ExecuteWithCapturedOutput("--no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void ItRunsWhenRestoringToSpecificPackageDir()
{
@ -62,7 +91,7 @@ namespace Microsoft.DotNet.Cli.Build.Tests
new BuildCommand()
.WithWorkingDirectory(rootPath)
.Execute()
.Execute("--no-restore")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

View file

@ -158,7 +158,7 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
}
[Fact]
public void PackWorksWithLocalProjectJson()
public void PackWorksWithLocalProject()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
@ -171,6 +171,33 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
.Should().Pass();
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenPackaging()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
.WithSourceFiles();
new PackCommand()
.WithWorkingDirectory(testInstance.Root)
.Execute()
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenPackagingWithTheNoRestoreOption()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
.WithSourceFiles();
new PackCommand()
.WithWorkingDirectory(testInstance.Root)
.ExecuteWithCapturedOutput("--no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void HasServiceableFlagWhenArgumentPassed()
{
@ -231,7 +258,7 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
new PackCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should()
.Pass();

View file

@ -44,6 +44,39 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenPublishing()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new PublishCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("--framework netcoreapp2.0")
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenPublishingWithTheNoRestoreOption()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new PublishCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--framework netcoreapp2.0 --no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void ItPublishesARunnableSelfContainedApp()
{
@ -170,7 +203,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
new PublishCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

View file

@ -37,6 +37,40 @@ namespace Microsoft.DotNet.Cli.Run.Tests
.And.HaveStdOutContaining("Hello World!");
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenRunning()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World!");
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenRunningWithTheNoRestoreOption()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void ItBuildsTheProjectBeforeRunning()
{
@ -160,7 +194,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests
new RunCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}

View file

@ -31,6 +31,43 @@ namespace Microsoft.DotNet.Cli.Test.Tests
result.ExitCode.Should().Be(1);
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenTesting()
{
string testAppName = "VSTestCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
result.ExitCode.Should().Be(1);
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenTestingWithTheNoRestoreOption()
{
string testAppName = "VSTestCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void XunitSingleTFM()
{
@ -161,14 +198,14 @@ namespace Microsoft.DotNet.Cli.Test.Tests
new BuildCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should()
.Pass()
.And.NotHaveStdErr();
CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-restore");
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
@ -209,6 +246,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests
.Execute()
.Should()
.Pass();
return testProjectDirectory;
}
}