dotnet-installer/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2016-01-13 00:36:31 +00:00
using System;
using System.IO;
using Microsoft.DotNet.ProjectModel;
2016-01-06 10:27:16 +00:00
namespace Microsoft.DotNet.Cli.Utils
{
2016-01-06 10:27:16 +00:00
public static class CoreHost
{
internal static string _hostDir;
internal static string _hostExePath;
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);
public static string HostExePath
{
get
{
if (_hostExePath == null)
{
_hostExePath = Path.Combine(HostDir, Constants.HostExecutableName);
}
return _hostExePath;
}
}
private static string HostDir
{
get
{
if (_hostDir == null)
{
_hostDir = Path.GetDirectoryName(Env.GetCommandPath(
Constants.HostExecutableName, new[] {string.Empty}));
}
return _hostDir;
}
}
public static void CopyTo(string destinationPath, string hostExeName)
{
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);
}
}
}
}