2017-11-21 20:10:06 -08:00
|
|
|
// 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;
|
|
|
|
using System.Collections.Generic;
|
2017-12-04 14:13:24 -08:00
|
|
|
using Microsoft.DotNet.Cli;
|
2018-01-11 13:54:02 -08:00
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2017-12-04 14:13:24 -08:00
|
|
|
using Microsoft.DotNet.ToolPackage;
|
2017-11-21 20:10:06 -08:00
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
|
|
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
|
|
|
|
2017-12-04 14:13:24 -08:00
|
|
|
namespace Microsoft.DotNet.Tools.Install.Tool
|
2017-11-21 20:10:06 -08:00
|
|
|
{
|
|
|
|
internal class ProjectRestorer : IProjectRestorer
|
|
|
|
{
|
|
|
|
public void Restore(
|
|
|
|
FilePath projectPath,
|
|
|
|
DirectoryPath assetJsonOutput,
|
2018-01-11 13:54:02 -08:00
|
|
|
FilePath? nugetconfig,
|
|
|
|
string source = null)
|
2017-11-21 20:10:06 -08:00
|
|
|
{
|
|
|
|
var argsToPassToRestore = new List<string>();
|
|
|
|
|
2017-12-04 14:13:24 -08:00
|
|
|
argsToPassToRestore.Add(projectPath.Value);
|
2017-11-21 20:10:06 -08:00
|
|
|
if (nugetconfig != null)
|
|
|
|
{
|
|
|
|
argsToPassToRestore.Add("--configfile");
|
2017-12-04 14:13:24 -08:00
|
|
|
argsToPassToRestore.Add(nugetconfig.Value.Value);
|
2017-11-21 20:10:06 -08:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:54:02 -08:00
|
|
|
if (source != null)
|
|
|
|
{
|
|
|
|
argsToPassToRestore.Add("--source");
|
|
|
|
argsToPassToRestore.Add(source);
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:10:06 -08:00
|
|
|
argsToPassToRestore.AddRange(new List<string>
|
|
|
|
{
|
|
|
|
"--runtime",
|
|
|
|
RuntimeEnvironment.GetRuntimeIdentifier(),
|
|
|
|
$"/p:BaseIntermediateOutputPath={assetJsonOutput.ToQuotedString()}"
|
|
|
|
});
|
|
|
|
|
|
|
|
var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
|
2018-01-11 13:54:02 -08:00
|
|
|
.Create("restore", argsToPassToRestore)
|
2017-11-21 20:10:06 -08:00
|
|
|
.CaptureStdOut()
|
|
|
|
.CaptureStdErr();
|
|
|
|
|
|
|
|
var result = command.Execute();
|
|
|
|
if (result.ExitCode != 0)
|
|
|
|
{
|
|
|
|
throw new PackageObtainException("Failed to restore package. " +
|
|
|
|
$"{Environment.NewLine}WorkingDirectory: " +
|
|
|
|
result.StartInfo.WorkingDirectory +
|
|
|
|
$"{Environment.NewLine}Arguments: " +
|
|
|
|
result.StartInfo.Arguments +
|
|
|
|
$"{Environment.NewLine}Output: " +
|
|
|
|
result.StdErr + result.StdOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|