@@ -75,23 +75,33 @@ private IEnumerable<string> SearchPaths
75
75
{
76
76
// e.g. on Linux the 'dotnet' command from PATH is a symlink so we need to
77
77
// resolve it to get the actual path to the binary
78
- dotnetExeFromPath = GetRealPath ( dotnetExeFromPath ) ?? dotnetExeFromPath ;
78
+ dotnetExeFromPath = GetRealPath ( dotnetExeFromPath ) ;
79
79
80
- static string ? GetRealPath ( string path )
80
+ static string GetRealPath ( string path )
81
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 )
82
+ FileInfo fileInfo = new ( path ) ;
83
+ if ( fileInfo . LinkTarget != null )
88
84
{
89
- var resolvedTarget = info . ResolveLinkTarget ( returnFinalTarget : true ) ;
90
- if ( resolvedTarget != null )
91
- return resolvedTarget . FullName ;
85
+ var resolved = fileInfo . ResolveLinkTarget ( true ) ;
86
+ return resolved ? . Exists is true ? resolved . FullName : path ;
92
87
}
93
-
94
- return fullPath ;
88
+
89
+ string invariantPart = string . Empty ;
90
+ DirectoryInfo ? parentDirectory = fileInfo . Directory ;
91
+ while ( parentDirectory is not null )
92
+ {
93
+ invariantPart = path [ parentDirectory . FullName . Length ..] ;
94
+ if ( parentDirectory . LinkTarget != null )
95
+ {
96
+ var resolved = parentDirectory . ResolveLinkTarget ( true ) ;
97
+ if ( resolved ? . Exists is true )
98
+ return Path . Join ( resolved . FullName , invariantPart ) ;
99
+ }
100
+
101
+ parentDirectory = parentDirectory . Parent ;
102
+ }
103
+
104
+ return path ;
95
105
}
96
106
}
97
107
#endif
0 commit comments