Skip to content

Commit f862035

Browse files
committed
Fix #101 - honor DOTNET_ROOT
1 parent 447b3e1 commit f862035

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/CommandLineUtils/Utilities/DotNetExe.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@ static DotNetExe()
2323

2424
/// <summary>
2525
/// The full filepath to the .NET Core CLI executable.
26+
/// <para>
27+
/// May be <c>null</c> if the CLI cannot be found. <seealso cref="FullPathOrDefault" />
28+
/// </para>
2629
/// </summary>
30+
/// /// <returns>The path or null</returns>
2731
public static string FullPath { get; }
2832

2933
/// <summary>
3034
/// Finds the full filepath to the .NET Core CLI executable,
3135
/// or returns a string containing the default name of the .NET Core muxer ('dotnet').
32-
/// </summary>
3336
/// <returns>The path or a string named 'dotnet'</returns>
37+
/// </summary>
3438
public static string FullPathOrDefault()
3539
=> FullPath ?? FileName;
3640

3741
private static string TryFindDotNetExePath()
3842
{
43+
var fileName = FileName;
3944
#if NET45
40-
return "dotnet.exe";
45+
fileName += ".exe";
4146
#elif (NETSTANDARD1_6 || NETSTANDARD2_0)
42-
var fileName = FileName;
43-
4447
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
4548
{
4649
fileName += ".exe";
@@ -52,11 +55,16 @@ private static string TryFindDotNetExePath()
5255
{
5356
return mainModule.FileName;
5457
}
55-
56-
return null;
5758
#else
5859
#error Update target frameworks
5960
#endif
61+
var dotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");
62+
if (!string.IsNullOrEmpty(dotnetRoot))
63+
{
64+
return Path.Combine(dotnetRoot, fileName);
65+
}
66+
67+
return null;
6068
}
6169
}
6270
}

0 commit comments

Comments
 (0)