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;
|
2018-01-13 09:40:48 -08:00
|
|
|
using Microsoft.DotNet.Tools;
|
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",
|
2018-01-22 10:45:35 -08:00
|
|
|
GetRuntimeIdentifierWithMacOsHighSierraFallback(),
|
2017-11-21 20:10:06 -08:00
|
|
|
$"/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)
|
|
|
|
{
|
2018-01-13 09:40:48 -08:00
|
|
|
throw new PackageObtainException(
|
|
|
|
string.Format(
|
|
|
|
LocalizableStrings.FailedToRestorePackage,
|
|
|
|
result.StartInfo.WorkingDirectory, result.StartInfo.Arguments, result.StdErr, result.StdOut));
|
2017-11-21 20:10:06 -08:00
|
|
|
}
|
|
|
|
}
|
2018-01-22 10:45:35 -08:00
|
|
|
|
|
|
|
// walk around for https://github.com/dotnet/corefx/issues/26488
|
|
|
|
// fallback osx.10.13 to osx
|
|
|
|
private static string GetRuntimeIdentifierWithMacOsHighSierraFallback()
|
|
|
|
{
|
|
|
|
if (RuntimeEnvironment.GetRuntimeIdentifier() == "osx.10.13-x64")
|
|
|
|
{
|
|
|
|
return "osx-x64";
|
|
|
|
}
|
|
|
|
|
|
|
|
return RuntimeEnvironment.GetRuntimeIdentifier();
|
|
|
|
}
|
2017-11-21 20:10:06 -08:00
|
|
|
}
|
|
|
|
}
|