src/redist/project.json

This commit is contained in:
Piotr Puszkiewicz 2016-08-09 13:22:22 -07:00
parent 912a47f672
commit 3a55a4182f
22 changed files with 235 additions and 100 deletions

View file

@ -1,107 +0,0 @@
// 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 Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace Microsoft.DotNet.Cli
{
/// <summary>
/// A class which encapsulates logic needed to forward arguments from the current process to another process
/// invoked with the dotnet.exe host.
/// </summary>
public class ForwardingApp
{
private const string s_hostExe = "dotnet";
private readonly string _forwardApplicationPath;
private readonly string[] _argsToForward;
private readonly string _depsFile;
private readonly string _runtimeConfig;
private readonly string _additionalProbingPath;
private readonly Dictionary<string, string> _environmentVariables;
private readonly string[] _allArgs;
public ForwardingApp(
string forwardApplicationPath,
string[] argsToForward,
string depsFile = null,
string runtimeConfig = null,
string additionalProbingPath = null,
Dictionary<string, string> environmentVariables = null)
{
_forwardApplicationPath = forwardApplicationPath;
_argsToForward = argsToForward;
_depsFile = depsFile;
_runtimeConfig = runtimeConfig;
_additionalProbingPath = additionalProbingPath;
_environmentVariables = environmentVariables;
var allArgs = new List<string>();
allArgs.Add("exec");
if (_depsFile != null)
{
allArgs.Add("--depsfile");
allArgs.Add(_depsFile);
}
if (_runtimeConfig != null)
{
allArgs.Add("--runtimeconfig");
allArgs.Add(_runtimeConfig);
}
if (_additionalProbingPath != null)
{
allArgs.Add("--additionalprobingpath");
allArgs.Add(_additionalProbingPath);
}
allArgs.Add(_forwardApplicationPath);
allArgs.AddRange(_argsToForward);
_allArgs = allArgs.ToArray();
}
public int Execute()
{
var processInfo = new ProcessStartInfo
{
FileName = GetHostExeName(),
Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(_allArgs),
UseShellExecute = false
};
if (_environmentVariables != null)
{
foreach (var entry in _environmentVariables)
{
processInfo.Environment[entry.Key] = entry.Value;
}
}
var process = new Process
{
StartInfo = processInfo
};
process.Start();
process.WaitForExit();
return process.ExitCode;
}
private string GetHostExeName()
{
return $"{s_hostExe}{FileNameSuffixes.CurrentPlatform.Exe}";
}
}
}

View file

@ -21,8 +21,6 @@ namespace Microsoft.DotNet.Cli
_forwardingApp = new ForwardingApp(
GetMSBuildExePath(),
argsToForward,
depsFile: GetDepsFile(),
runtimeConfig: GetRuntimeConfig(),
environmentVariables: GetEnvironmentVariables());
}
@ -56,19 +54,18 @@ namespace Microsoft.DotNet.Cli
private static string GetRuntimeConfig()
{
return Path.Combine(AppContext.BaseDirectory, "dotnet.runtimeconfig.json");
return Path.Combine(AppContext.BaseDirectory, "msbuild.runtimeconfig.json");
}
private static string GetDepsFile()
{
return Path.Combine(AppContext.BaseDirectory, "dotnet.deps.json");
return Path.Combine(AppContext.BaseDirectory, "msbuild.deps.json");
}
private static string GetMSBuildExePath()
{
return Path.Combine(
AppContext.BaseDirectory,
"runtimes", "any", "native",
s_msbuildExeName);
}

View file

@ -4,7 +4,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.DotNet.Cli.Utils;
using NugetProgram = NuGet.CommandLine.XPlat.Program;
namespace Microsoft.DotNet.Tools.Restore
{
@ -20,18 +19,11 @@ namespace Microsoft.DotNet.Tools.Restore
}
prefixArgs.Add("restore");
var result = Run(Enumerable.Concat(
var result = new NuGetForwardingApp(Enumerable.Concat(
prefixArgs,
args).ToArray());
args).ToArray()).Execute();
return result;
}
private static int Run(string[] nugetArgs)
{
var nugetAsm = typeof(NugetProgram).GetTypeInfo().Assembly;
var mainMethod = nugetAsm.EntryPoint;
return (int)mainMethod.Invoke(null, new object[] { nugetArgs });
}
}
}

View file

@ -0,0 +1,44 @@
// 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 Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.DotNet.Tools.Restore
{
public class NuGetForwardingApp
{
private const string s_nugetExeName = "NuGet.CommandLine.XPlat.dll";
private readonly ForwardingApp _forwardingApp;
public NuGetForwardingApp(string[] argsToForward)
{
_forwardingApp = new ForwardingApp(
GetNuGetExePath(),
argsToForward);
}
public int Execute()
{
return _forwardingApp.Execute();
}
private static string GetHostPath()
{
return new Muxer().MuxerPath;
}
private static string GetNuGetExePath()
{
return Path.Combine(
AppContext.BaseDirectory,
s_nugetExeName);
}
}
}

View file

@ -17,35 +17,7 @@ namespace Microsoft.DotNet.Tools.Restore
{
DebugHelper.HandleDebugSwitch(ref args);
var app = new CommandLineApplication(false)
{
Name = "dotnet restore",
FullName = ".NET project dependency restorer",
Description = "Restores dependencies listed in project.json"
};
app.OnExecute(() =>
{
try
{
return NuGet3.Restore(args);
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
return -1;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return -2;
}
});
return app.Execute(args);
return NuGet3.Restore(args);
}
}
}