2016-01-13 00:36:31 +00:00
|
|
|
using System;
|
2016-01-04 20:49:13 +00:00
|
|
|
using System.IO;
|
|
|
|
using Microsoft.DotNet.ProjectModel;
|
|
|
|
|
2016-01-06 10:27:16 +00:00
|
|
|
namespace Microsoft.DotNet.Cli.Utils
|
2016-01-04 20:49:13 +00:00
|
|
|
{
|
2016-01-06 10:27:16 +00:00
|
|
|
public static class CoreHost
|
2016-01-04 20:49:13 +00:00
|
|
|
{
|
2016-01-10 07:33:22 +00:00
|
|
|
internal static string _hostDir;
|
|
|
|
internal static string _hostExePath;
|
2016-01-04 20:49:13 +00:00
|
|
|
|
2016-01-13 00:36:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the path to the version of corehost that was shipped with this command
|
|
|
|
/// </summary>
|
|
|
|
public static string LocalHostExePath => Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
|
|
|
|
2016-01-10 07:33:22 +00:00
|
|
|
public static string HostExePath
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_hostExePath == null)
|
|
|
|
{
|
|
|
|
_hostExePath = Path.Combine(HostDir, Constants.HostExecutableName);
|
|
|
|
}
|
|
|
|
return _hostExePath;
|
|
|
|
}
|
|
|
|
}
|
2016-01-04 20:49:13 +00:00
|
|
|
|
2016-01-10 07:33:22 +00:00
|
|
|
private static string HostDir
|
2016-01-04 20:49:13 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2016-01-10 07:33:22 +00:00
|
|
|
if (_hostDir == null)
|
2016-01-04 20:49:13 +00:00
|
|
|
{
|
2016-01-10 07:33:22 +00:00
|
|
|
_hostDir = Path.GetDirectoryName(Env.GetCommandPath(
|
|
|
|
Constants.HostExecutableName, new[] {string.Empty}));
|
2016-01-04 20:49:13 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 07:33:22 +00:00
|
|
|
return _hostDir;
|
2016-01-04 20:49:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 07:33:22 +00:00
|
|
|
public static void CopyTo(string destinationPath, string hostExeName)
|
2016-01-04 20:49:13 +00:00
|
|
|
{
|
2016-01-10 07:33:22 +00:00
|
|
|
foreach (var binaryName in Constants.HostBinaryNames)
|
|
|
|
{
|
|
|
|
var outputBinaryName = binaryName.Equals(Constants.HostExecutableName)
|
|
|
|
? hostExeName : binaryName;
|
|
|
|
var outputBinaryPath = Path.Combine(destinationPath, outputBinaryName);
|
|
|
|
var hostBinaryPath = Path.Combine(HostDir, binaryName);
|
|
|
|
File.Copy(hostBinaryPath, outputBinaryPath, overwrite: true);
|
|
|
|
}
|
2016-01-04 20:49:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-10 07:33:22 +00:00
|
|
|
}
|