File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -831,12 +831,32 @@ module DotNet =
831831
832832 let currentDotNetRoot = Environment.environVar " DOTNET_ROOT"
833833
834+ // resolve potential symbolic link to the real location
835+ // On .NET we can use File.ResolveLinkTarget, on .NET Standard we use Mono.Unix.UnixPath.GetRealPath
836+ let resolveLinkTarget linkPath =
837+
838+ let resolvedPath =
839+ #if NET
840+ // ResolveLinkTarget returns null if the input isn't a link. Just use the input path directly in that case.
841+ // @@TODO@@ ResolveLinkTarget might throw if the input doesn't exist - maybe need to handle that.
842+ let resolvedTarget = File.ResolveLinkTarget( linkPath, true )
843+
844+ if isNull resolvedTarget then
845+ linkPath
846+ else
847+ resolvedTarget.FullName
848+ #else
849+ // https://stackoverflow.com/questions/58326739/how-can-i-find-the-target-of-a-linux-symlink-in-c-sharp
850+ Mono.Unix.UnixPath.GetRealPath( dotnetTool)
851+ #endif
852+
853+ resolvedPath |> Path.GetDirectoryName
854+
834855 let realFolder =
835856 if not Environment.isWindows then
836857#if ! FX_ NO_ POSIX
837858 // resolve potential symbolic link to the real location
838- // https://stackoverflow.com/questions/58326739/how-can-i-find-the-target-of-a-linux-symlink-in-c-sharp
839- Mono.Unix.UnixPath.GetRealPath( dotnetTool) |> Path.GetDirectoryName
859+ resolveLinkTarget dotnetTool
840860#else
841861 eprintf
842862 " Setting 'DOTNET_ROOT' to '%s ' this might be wrong as we didn't follow the symlink. Please upgrade to netcore."
You can’t perform that action at this time.
0 commit comments