Fixing windows build and addressing code review comments.
This commit is contained in:
parent
5b3cd63198
commit
79a817bbc7
5 changed files with 12 additions and 29 deletions
|
@ -12,7 +12,6 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
internal class EnvironmentProvider
|
internal class EnvironmentProvider
|
||||||
{
|
{
|
||||||
private IEnumerable<string> _searchPaths;
|
private IEnumerable<string> _searchPaths;
|
||||||
private IEnumerable<string> _executableExtensions;
|
|
||||||
|
|
||||||
private readonly Func<string, string> _getEnvironmentVariable;
|
private readonly Func<string, string> _getEnvironmentVariable;
|
||||||
|
|
||||||
|
@ -21,21 +20,11 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
_getEnvironmentVariable = getEnvironmentVariable;
|
_getEnvironmentVariable = getEnvironmentVariable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ExecutableExtensions
|
public string ExecutableExtension
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_executableExtensions == null)
|
return Interop.RunningOnWindows ? ".exe" : string.Empty;
|
||||||
{
|
|
||||||
|
|
||||||
_executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
||||||
? _getEnvironmentVariable("PATHEXT")
|
|
||||||
.Split(';')
|
|
||||||
.Select(e => e.ToLower().Trim('"'))
|
|
||||||
: new [] { string.Empty };
|
|
||||||
}
|
|
||||||
|
|
||||||
return _executableExtensions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +34,7 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
{
|
{
|
||||||
if (_searchPaths == null)
|
if (_searchPaths == null)
|
||||||
{
|
{
|
||||||
var searchPaths = new List<string> { GetApplicationBasePath() };
|
var searchPaths = new List<string>();
|
||||||
|
|
||||||
searchPaths.AddRange(
|
searchPaths.AddRange(
|
||||||
_getEnvironmentVariable("PATH")
|
_getEnvironmentVariable("PATH")
|
||||||
|
@ -61,18 +50,12 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
|
|
||||||
public string GetCommandPath(string commandName)
|
public string GetCommandPath(string commandName)
|
||||||
{
|
{
|
||||||
var commandPath = SearchPaths.Join(
|
var commandNameWithExtension = commandName + ExecutableExtension;
|
||||||
ExecutableExtensions.ToArray(),
|
var commandPath = SearchPaths
|
||||||
p => true, s => true,
|
.Select(p => Path.Combine(p, commandNameWithExtension))
|
||||||
(p, s) => Path.Combine(p, commandName + s))
|
|
||||||
.FirstOrDefault(File.Exists);
|
.FirstOrDefault(File.Exists);
|
||||||
|
|
||||||
return commandPath;
|
return commandPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetApplicationBasePath()
|
|
||||||
{
|
|
||||||
return Path.GetFullPath(AppContext.BaseDirectory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
{
|
{
|
||||||
internal static partial class Interop
|
internal static partial class Interop
|
||||||
{
|
{
|
||||||
|
internal static readonly bool RunningOnWindows = true;
|
||||||
|
|
||||||
static Interop()
|
static Interop()
|
||||||
{
|
{
|
||||||
PreloadLibrary("hostfxr.dll");
|
PreloadLibrary("hostfxr.dll");
|
||||||
|
|
|
@ -14,13 +14,13 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
{
|
{
|
||||||
internal static partial class Interop
|
internal static partial class Interop
|
||||||
{
|
{
|
||||||
internal static readonly bool s_runningOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
internal static readonly bool RunningOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
|
|
||||||
private static int hostfxr_resolve_sdk(string exe_dir, string working_dir, [Out] StringBuilder buffer, int buffer_size)
|
private static int hostfxr_resolve_sdk(string exe_dir, string working_dir, [Out] StringBuilder buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
// hostfxr string encoding is platform -specific so dispatch to the
|
// hostfxr string encoding is platform -specific so dispatch to the
|
||||||
// appropriately annotated P/Invoke for the current platform.
|
// appropriately annotated P/Invoke for the current platform.
|
||||||
return s_runningOnWindows
|
return RunningOnWindows
|
||||||
? windows_hostfxr_resolve_sdk(exe_dir, working_dir, buffer, buffer_size)
|
? windows_hostfxr_resolve_sdk(exe_dir, working_dir, buffer, buffer_size)
|
||||||
: unix_hostfxr_resolve_sdk(exe_dir, working_dir, buffer, buffer_size);
|
: unix_hostfxr_resolve_sdk(exe_dir, working_dir, buffer, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,14 +106,14 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
|
|
||||||
private string ResolveNetcoreSdkDirectory(SdkResolverContext context)
|
private string ResolveNetcoreSdkDirectory(SdkResolverContext context)
|
||||||
{
|
{
|
||||||
string exeDir = GetDotnetExeDirectoryCandidates();
|
string exeDir = GetDotnetExeDirectory();
|
||||||
string workingDir = context.SolutionFilePath ?? context.ProjectFilePath;
|
string workingDir = context.SolutionFilePath ?? context.ProjectFilePath;
|
||||||
string netcoreSdkDir = Interop.hostfxr_resolve_sdk(exeDir, workingDir);
|
string netcoreSdkDir = Interop.hostfxr_resolve_sdk(exeDir, workingDir);
|
||||||
|
|
||||||
return netcoreSdkDir;
|
return netcoreSdkDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetDotnetExeDirectoryCandidates()
|
private string GetDotnetExeDirectory()
|
||||||
{
|
{
|
||||||
string environmentOverride = _getEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR");
|
string environmentOverride = _getEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR");
|
||||||
if (environmentOverride != null)
|
if (environmentOverride != null)
|
||||||
|
|
|
@ -175,8 +175,6 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
{
|
{
|
||||||
case "PATH":
|
case "PATH":
|
||||||
return PathEnvironmentVariable;
|
return PathEnvironmentVariable;
|
||||||
case "PATHEX":
|
|
||||||
return ".exe";
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue