Skip to content

Commit b758b92

Browse files
committed
fix: fixes ApplicationHelper.GetDotnetPath
1 parent 72c0ca9 commit b758b92

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/WeihanLi.Common/Helpers/ApplicationHelper.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,17 @@ public static string GetDotnetDirectory()
7373
{
7474
return environmentOverride;
7575
}
76+
environmentOverride = Environment.GetEnvironmentVariable("DOTNET_ROOT");
77+
if (!string.IsNullOrEmpty(environmentOverride))
78+
{
79+
return environmentOverride;
80+
}
7681

7782
var dotnetExe = GetDotnetPath();
7883

7984
if (dotnetExe.IsNotNullOrEmpty() && !InteropHelper.RunningOnWindows)
8085
{
81-
// e.g. on Linux the 'dotnet' command from PATH is a symlink so we need to
86+
// e.g. on Linux the 'dotnet' command from PATH is a symbol link so we need to
8287
// resolve it to get the actual path to the binary
8388
dotnetExe = InteropHelper.Unix.RealPath(dotnetExe) ?? dotnetExe;
8489
}
@@ -97,15 +102,15 @@ public static string GetDotnetDirectory()
97102

98103
public static string? ResolvePath(string execName) => ResolvePath(execName, ".exe");
99104

100-
public static string? ResolvePath(string execName, string? ext)
105+
public static string? ResolvePath(string execName, string? windowsExt)
101106
{
102107
var executableName = execName;
103108
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
104109
&& !Path.HasExtension(execName)
105-
&& string.IsNullOrEmpty(ext)
110+
&& !string.IsNullOrEmpty(windowsExt)
106111
)
107112
{
108-
executableName += ext;
113+
executableName = $"{executableName}{windowsExt}";
109114
}
110115
var searchPaths = Guard.NotNull(Environment.GetEnvironmentVariable("PATH"))
111116
.Split(new[] { Path.PathSeparator }, options: StringSplitOptions.RemoveEmptyEntries)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Weihan Li. All rights reserved.
2+
// Licensed under the Apache license.
3+
4+
using WeihanLi.Common.Helpers;
5+
using Xunit;
6+
7+
namespace WeihanLi.Common.Test.HelpersTest;
8+
public class ApplicationHelperTest
9+
{
10+
[Fact]
11+
public void DotnetPathTest()
12+
{
13+
var dotnetPath = ApplicationHelper.GetDotnetPath();
14+
Assert.NotNull(dotnetPath);
15+
Assert.NotEmpty(dotnetPath);
16+
}
17+
}

0 commit comments

Comments
 (0)