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
|
||||
{
|
||||
private IEnumerable<string> _searchPaths;
|
||||
private IEnumerable<string> _executableExtensions;
|
||||
|
||||
private readonly Func<string, string> _getEnvironmentVariable;
|
||||
|
||||
|
@ -21,21 +20,11 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
_getEnvironmentVariable = getEnvironmentVariable;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ExecutableExtensions
|
||||
public string ExecutableExtension
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_executableExtensions == null)
|
||||
{
|
||||
|
||||
_executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
? _getEnvironmentVariable("PATHEXT")
|
||||
.Split(';')
|
||||
.Select(e => e.ToLower().Trim('"'))
|
||||
: new [] { string.Empty };
|
||||
}
|
||||
|
||||
return _executableExtensions;
|
||||
return Interop.RunningOnWindows ? ".exe" : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +34,7 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
{
|
||||
if (_searchPaths == null)
|
||||
{
|
||||
var searchPaths = new List<string> { GetApplicationBasePath() };
|
||||
var searchPaths = new List<string>();
|
||||
|
||||
searchPaths.AddRange(
|
||||
_getEnvironmentVariable("PATH")
|
||||
|
@ -61,18 +50,12 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
|
||||
public string GetCommandPath(string commandName)
|
||||
{
|
||||
var commandPath = SearchPaths.Join(
|
||||
ExecutableExtensions.ToArray(),
|
||||
p => true, s => true,
|
||||
(p, s) => Path.Combine(p, commandName + s))
|
||||
var commandNameWithExtension = commandName + ExecutableExtension;
|
||||
var commandPath = SearchPaths
|
||||
.Select(p => Path.Combine(p, commandNameWithExtension))
|
||||
.FirstOrDefault(File.Exists);
|
||||
|
||||
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 readonly bool RunningOnWindows = true;
|
||||
|
||||
static Interop()
|
||||
{
|
||||
PreloadLibrary("hostfxr.dll");
|
||||
|
|
|
@ -14,13 +14,13 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
{
|
||||
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)
|
||||
{
|
||||
// hostfxr string encoding is platform -specific so dispatch to the
|
||||
// appropriately annotated P/Invoke for the current platform.
|
||||
return s_runningOnWindows
|
||||
return RunningOnWindows
|
||||
? windows_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)
|
||||
{
|
||||
string exeDir = GetDotnetExeDirectoryCandidates();
|
||||
string exeDir = GetDotnetExeDirectory();
|
||||
string workingDir = context.SolutionFilePath ?? context.ProjectFilePath;
|
||||
string netcoreSdkDir = Interop.hostfxr_resolve_sdk(exeDir, workingDir);
|
||||
|
||||
return netcoreSdkDir;
|
||||
}
|
||||
|
||||
private string GetDotnetExeDirectoryCandidates()
|
||||
private string GetDotnetExeDirectory()
|
||||
{
|
||||
string environmentOverride = _getEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR");
|
||||
if (environmentOverride != null)
|
||||
|
|
|
@ -175,8 +175,6 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
|||
{
|
||||
case "PATH":
|
||||
return PathEnvironmentVariable;
|
||||
case "PATHEX":
|
||||
return ".exe";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue