From 45bb3c1842b1158d5f43a04cf0ad8bf93b38415f Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Mon, 4 Mar 2024 22:20:49 +0000 Subject: [PATCH] More robust runtime detector --- src/Ionide.ProjInfo/Utils.fs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Ionide.ProjInfo/Utils.fs b/src/Ionide.ProjInfo/Utils.fs index 5e9e2d6c..14d81b56 100644 --- a/src/Ionide.ProjInfo/Utils.fs +++ b/src/Ionide.ProjInfo/Utils.fs @@ -91,6 +91,24 @@ module Paths = else None + let private tryFindFromSelf () = + let rec findDotnetAbove (self: DirectoryInfo) = + match self.Parent with + | null -> None + | parent -> + let candidate = + Path.Combine(parent.FullName, dotnetBinaryName) + |> FileInfo + |> checkExistence + + match candidate with + | Some candidate -> Some candidate + | None -> findDotnetAbove parent + + RuntimeEnvironment.GetRuntimeDirectory() + |> DirectoryInfo + |> findDotnetAbove + /// /// provides the path to the `dotnet` binary running this library, respecting various dotnet environment variables. /// Also probes the PATH and checks the default installation locations @@ -98,6 +116,7 @@ module Paths = let dotnetRoot = lazy (tryFindFromEnvVar () + |> Option.orElseWith tryFindFromSelf |> Option.orElseWith tryFindFromPATH |> Option.orElseWith tryFindFromDefaultDirs)