Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 79a817b

Browse files
Livar Cunhalivarcocc
authored andcommitted
Fixing windows build and addressing code review comments.
1 parent 5b3cd63 commit 79a817b

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

src/Microsoft.DotNet.MSBuildSdkResolver/EnvironmentProvider.cs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
1212
internal class EnvironmentProvider
1313
{
1414
private IEnumerable<string> _searchPaths;
15-
private IEnumerable<string> _executableExtensions;
1615

1716
private readonly Func<string, string> _getEnvironmentVariable;
1817

@@ -21,21 +20,11 @@ public EnvironmentProvider(Func<string, string> getEnvironmentVariable)
2120
_getEnvironmentVariable = getEnvironmentVariable;
2221
}
2322

24-
public IEnumerable<string> ExecutableExtensions
23+
public string ExecutableExtension
2524
{
2625
get
2726
{
28-
if (_executableExtensions == null)
29-
{
30-
31-
_executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
32-
? _getEnvironmentVariable("PATHEXT")
33-
.Split(';')
34-
.Select(e => e.ToLower().Trim('"'))
35-
: new [] { string.Empty };
36-
}
37-
38-
return _executableExtensions;
27+
return Interop.RunningOnWindows ? ".exe" : string.Empty;
3928
}
4029
}
4130

@@ -45,7 +34,7 @@ private IEnumerable<string> SearchPaths
4534
{
4635
if (_searchPaths == null)
4736
{
48-
var searchPaths = new List<string> { GetApplicationBasePath() };
37+
var searchPaths = new List<string>();
4938

5039
searchPaths.AddRange(
5140
_getEnvironmentVariable("PATH")
@@ -61,18 +50,12 @@ private IEnumerable<string> SearchPaths
6150

6251
public string GetCommandPath(string commandName)
6352
{
64-
var commandPath = SearchPaths.Join(
65-
ExecutableExtensions.ToArray(),
66-
p => true, s => true,
67-
(p, s) => Path.Combine(p, commandName + s))
53+
var commandNameWithExtension = commandName + ExecutableExtension;
54+
var commandPath = SearchPaths
55+
.Select(p => Path.Combine(p, commandNameWithExtension))
6856
.FirstOrDefault(File.Exists);
6957

7058
return commandPath;
7159
}
72-
73-
private static string GetApplicationBasePath()
74-
{
75-
return Path.GetFullPath(AppContext.BaseDirectory);
76-
}
7760
}
7861
}

src/Microsoft.DotNet.MSBuildSdkResolver/Interop.NETFramework.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
1212
{
1313
internal static partial class Interop
1414
{
15+
internal static readonly bool RunningOnWindows = true;
16+
1517
static Interop()
1618
{
1719
PreloadLibrary("hostfxr.dll");

src/Microsoft.DotNet.MSBuildSdkResolver/Interop.NETStandard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
1414
{
1515
internal static partial class Interop
1616
{
17-
internal static readonly bool s_runningOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
17+
internal static readonly bool RunningOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
1818

1919
private static int hostfxr_resolve_sdk(string exe_dir, string working_dir, [Out] StringBuilder buffer, int buffer_size)
2020
{
2121
// hostfxr string encoding is platform -specific so dispatch to the
2222
// appropriately annotated P/Invoke for the current platform.
23-
return s_runningOnWindows
23+
return RunningOnWindows
2424
? windows_hostfxr_resolve_sdk(exe_dir, working_dir, buffer, buffer_size)
2525
: unix_hostfxr_resolve_sdk(exe_dir, working_dir, buffer, buffer_size);
2626
}

src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ private bool IsNetCoreSDKSmallerThanTheMinimumVersion(string netcoreSdkVersion,
106106

107107
private string ResolveNetcoreSdkDirectory(SdkResolverContext context)
108108
{
109-
string exeDir = GetDotnetExeDirectoryCandidates();
109+
string exeDir = GetDotnetExeDirectory();
110110
string workingDir = context.SolutionFilePath ?? context.ProjectFilePath;
111111
string netcoreSdkDir = Interop.hostfxr_resolve_sdk(exeDir, workingDir);
112112

113113
return netcoreSdkDir;
114114
}
115115

116-
private string GetDotnetExeDirectoryCandidates()
116+
private string GetDotnetExeDirectory()
117117
{
118118
string environmentOverride = _getEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR");
119119
if (environmentOverride != null)

test/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ public string GetEnvironmentVariable(string variable)
175175
{
176176
case "PATH":
177177
return PathEnvironmentVariable;
178-
case "PATHEX":
179-
return ".exe";
180178
default:
181179
return null;
182180
}

0 commit comments

Comments
 (0)