@@ -59,7 +59,7 @@ private IEnumerable<string> SearchPaths
59
59
}
60
60
61
61
string ? dotnetExe ;
62
- #if NETCOREAPP
62
+ #if NET
63
63
// The dotnet executable is loading only the .NET version of this code so there is no point checking
64
64
// the current process path on .NET Framework. We are expected to find dotnet on PATH.
65
65
dotnetExe = _getCurrentProcessPath ( ) ;
@@ -70,12 +70,31 @@ private IEnumerable<string> SearchPaths
70
70
{
71
71
string ? dotnetExeFromPath = GetCommandPath ( Constants . DotNet ) ;
72
72
73
- if ( dotnetExeFromPath != null && ! Interop . RunningOnWindows )
73
+ #if NET
74
+ if ( dotnetExeFromPath != null && ! OperatingSystem . IsWindows ( ) )
74
75
{
75
76
// e.g. on Linux the 'dotnet' command from PATH is a symlink so we need to
76
77
// resolve it to get the actual path to the binary
77
- dotnetExeFromPath = Interop . Unix . realpath ( dotnetExeFromPath ) ?? dotnetExeFromPath ;
78
+ dotnetExeFromPath = GetRealPath ( dotnetExeFromPath ) ?? dotnetExeFromPath ;
79
+
80
+ static string ? GetRealPath ( string path )
81
+ {
82
+ string fullPath = Path . GetFullPath ( path ) ;
83
+ if ( ! File . Exists ( fullPath ) )
84
+ return null ;
85
+
86
+ FileInfo info = new ( fullPath ) ;
87
+ if ( info . LinkTarget != null )
88
+ {
89
+ var resolvedTarget = info . ResolveLinkTarget ( returnFinalTarget : true ) ;
90
+ if ( resolvedTarget != null )
91
+ return resolvedTarget . FullName ;
92
+ }
93
+
94
+ return fullPath ;
95
+ }
78
96
}
97
+ #endif
79
98
80
99
if ( ! string . IsNullOrWhiteSpace ( dotnetExeFromPath ) )
81
100
{
@@ -86,7 +105,7 @@ private IEnumerable<string> SearchPaths
86
105
log ? . Invoke ( $ "GetDotnetExeDirectory: dotnet command path not found. Using current process") ;
87
106
log ? . Invoke ( $ "GetDotnetExeDirectory: Path variable: { _getEnvironmentVariable ( Constants . PATH ) } ") ;
88
107
89
- #if ! NETCOREAPP
108
+ #if ! NET
90
109
// If we failed to find dotnet on PATH, we revert to the old behavior of returning the current process
91
110
// path. This is really an error state but we're keeping the contract of always returning a non-empty
92
111
// path for backward compatibility.
@@ -123,7 +142,7 @@ private IEnumerable<string> SearchPaths
123
142
private static string ? GetCurrentProcessPath ( )
124
143
{
125
144
string ? currentProcessPath ;
126
- #if NET6_0_OR_GREATER
145
+ #if NET
127
146
currentProcessPath = Environment . ProcessPath ;
128
147
#else
129
148
currentProcessPath = Process . GetCurrentProcess ( ) . MainModule . FileName ;
0 commit comments