Skip to content

Commit 284c52a

Browse files
committed
Try using File.ResolveLinkTarget instead of Mono.Unix.UnixPath.GetRealPath on .NET (Core)
1 parent 74e1e6f commit 284c52a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/app/Fake.DotNet.Cli/DotNet.fs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff 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."

0 commit comments

Comments
 (0)