diff --git a/src/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs b/src/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs index 731713aa5..f862ba83d 100644 --- a/src/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs +++ b/src/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs @@ -166,12 +166,14 @@ namespace Microsoft.DotNet.Cli.Utils public ICommand CaptureStdErr() { _stdErr.Capture(); + return this; } public ICommand CaptureStdOut() { _stdOut.Capture(); + return this; } diff --git a/src/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Microsoft.DotNet.Cli.Utils/Command.cs index 212f8e138..59918cd4e 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Command.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Command.cs @@ -160,7 +160,7 @@ namespace Microsoft.DotNet.Cli.Utils #endif return new CommandResult( - this._process.StartInfo, + _process.StartInfo, exitCode, _stdOut?.CapturedOutput, _stdErr?.CapturedOutput); diff --git a/src/Microsoft.DotNet.Configurer/NuGetCachePrimer.cs b/src/Microsoft.DotNet.Configurer/NuGetCachePrimer.cs index fe644332b..a27ade4c3 100644 --- a/src/Microsoft.DotNet.Configurer/NuGetCachePrimer.cs +++ b/src/Microsoft.DotNet.Configurer/NuGetCachePrimer.cs @@ -11,9 +11,13 @@ namespace Microsoft.DotNet.Configurer public class NuGetCachePrimer : INuGetCachePrimer { private readonly ICommandFactory _commandFactory; + private readonly IDirectory _directory; + private readonly IFile _file; + private readonly INuGetPackagesArchiver _nugetPackagesArchiver; + private readonly INuGetCacheSentinel _nuGetCacheSentinel; public NuGetCachePrimer( @@ -36,9 +40,13 @@ namespace Microsoft.DotNet.Configurer IFile file) { _commandFactory = commandFactory; + _directory = directory; + _nugetPackagesArchiver = nugetPackagesArchiver; + _nuGetCacheSentinel = nuGetCacheSentinel; + _file = file; } @@ -64,12 +72,14 @@ namespace Microsoft.DotNet.Configurer using (var temporaryDotnetNewDirectory = _directory.CreateTemporaryDirectory()) { var workingDirectory = temporaryDotnetNewDirectory.DirectoryPath; + var createProjectSucceeded = CreateTemporaryProject(workingDirectory); if (createProjectSucceeded) { var restoreProjectSucceeded = RestoreTemporaryProject(extractedPackagesArchiveDirectory, workingDirectory); + if (restoreProjectSucceeded) { _nuGetCacheSentinel.CreateIfNotExists(); @@ -93,8 +103,8 @@ namespace Microsoft.DotNet.Configurer private bool RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory) { - var command = _commandFactory - .Create(commandToExecute, args) + var command = _commandFactory + .Create(commandToExecute, args) .WorkingDirectory(workingDirectory) .CaptureStdOut() .CaptureStdErr(); @@ -104,6 +114,7 @@ namespace Microsoft.DotNet.Configurer if (commandResult.ExitCode != 0) { Reporter.Verbose.WriteLine(commandResult.StdErr); + Reporter.Error.WriteLine( $"Failed to create prime the NuGet cache. {commandToExecute} failed with: {commandResult.ExitCode}"); } diff --git a/src/dotnet/DotNetCommandFactory.cs b/src/dotnet/DotNetCommandFactory.cs index d7f8eba62..8ead957d6 100644 --- a/src/dotnet/DotNetCommandFactory.cs +++ b/src/dotnet/DotNetCommandFactory.cs @@ -11,6 +11,13 @@ namespace Microsoft.DotNet.Cli { public class DotNetCommandFactory : ICommandFactory { + private bool _alwaysRunOutOfProc; + + public DotNetCommandFactory(bool alwaysRunOutOfProc = false) + { + _alwaysRunOutOfProc = alwaysRunOutOfProc; + } + public ICommand Create( string commandName, IEnumerable<string> args, @@ -18,7 +25,7 @@ namespace Microsoft.DotNet.Cli string configuration = Constants.DefaultConfiguration) { Func<string[], int> builtInCommand; - if (Program.TryGetBuiltInCommand(commandName, out builtInCommand)) + if (!_alwaysRunOutOfProc && Program.TryGetBuiltInCommand(commandName, out builtInCommand)) { Debug.Assert(framework == null, "BuiltInCommand doesn't support the 'framework' argument."); Debug.Assert(configuration == Constants.DefaultConfiguration, "BuiltInCommand doesn't support the 'configuration' argument."); diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 429f4567a..f0165ed1f 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -198,7 +198,7 @@ namespace Microsoft.DotNet.Cli using (var nugetPackagesArchiver = new NuGetPackagesArchiver()) { var environmentProvider = new EnvironmentProvider(); - var commandFactory = new DotNetCommandFactory(); + var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); var nugetCachePrimer = new NuGetCachePrimer(commandFactory, nugetPackagesArchiver, nugetCacheSentinel); var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( diff --git a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs index 938e97b60..7b3710828 100644 --- a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs +++ b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs @@ -57,7 +57,7 @@ namespace Microsoft.DotNet.Tests [Fact] public void It_shows_the_appropriate_message_to_the_user() { - const string firstTimeUseWelcomeMessage = @"Welcome to .NET Core! + string firstTimeUseWelcomeMessage = NormalizeLineEndings(@"Welcome to .NET Core! --------------------- Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs. Telemetry @@ -67,12 +67,12 @@ You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environmen You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry. Configuring... ------------------- -A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once."; +A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once."); // normalizing line endings as git is occasionally replacing line endings in this file causing this test to fail NormalizeLineEndings(_firstDotnetVerbUseCommandResult.StdOut) - .Should() - .StartWith(NormalizeLineEndings(firstTimeUseWelcomeMessage)); + .Should().StartWith(firstTimeUseWelcomeMessage) + .And.NotContain("Restore completed in"); } [Fact]