From 828443ecee9263c558d30371c96cfe6a08104907 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Tue, 12 Apr 2022 13:15:46 +0800 Subject: [PATCH] Paket.Core: honor DOTNET_ROOT env var [note: UNTESTED, DO NOT MERGE yet] Fixes https://github.com/fsprojects/Paket/issues/4141 --- src/Paket.Core/Common/ProcessHelper.fs | 20 +++++++++++++------- src/Paket.Core/Common/Utils.fs | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Paket.Core/Common/ProcessHelper.fs b/src/Paket.Core/Common/ProcessHelper.fs index 6884329707..f9f887d011 100644 --- a/src/Paket.Core/Common/ProcessHelper.fs +++ b/src/Paket.Core/Common/ProcessHelper.fs @@ -68,9 +68,14 @@ let isValidPath (path:string) = |> Array.filter (fun char -> path.Contains(char.ToString())) |> Array.isEmpty -/// Gets the list of valid directories included in the PATH environment variable. +/// Gets the list of valid directories included in the DOTNET_ROOT and PATH environment variables. let pathDirectories = - splitEnvironVar "PATH" + let pathEnvVarItems = splitEnvironVar "PATH" + let allPaths = + match environVarOrNone "DOTNET_ROOT" with + | None -> pathEnvVarItems + | Some dotnetRootPath -> dotnetRootPath::pathEnvVarItems + allPaths |> Seq.map (fun value -> value.Trim()) |> Seq.filter (fun value -> not (String.IsNullOrEmpty value) && isValidPath value) @@ -84,6 +89,12 @@ let tryFindFileOnPath (file : string) : string option = |> Seq.append [ "." ] |> fun path -> tryFindFile path file +let dotnetExe = + let exeName = if isUnix then "dotnet" else "dotnet.exe" + match tryFindFileOnPath exeName with + | Some exe -> exe + | None -> exeName + /// Modifies the ProcessStartInfo according to the platform semantics let platformInfoAction (psi : ProcessStartInfo) = if isMonoRuntime && psi.FileName.EndsWith ".exe" then @@ -92,11 +103,6 @@ let platformInfoAction (psi : ProcessStartInfo) = if psi.FileName.ToLowerInvariant().EndsWith(".dll") then // Run DotNetCore - let exeName = if isUnix then "dotnet" else "dotnet.exe" - let dotnetExe = - match tryFindFileOnPath exeName with - | Some exe -> exe - | None -> exeName psi.Arguments <- "\"" + psi.FileName + "\" " + psi.Arguments psi.FileName <- dotnetExe diff --git a/src/Paket.Core/Common/Utils.fs b/src/Paket.Core/Common/Utils.fs index 49fb182475..7807dbd7a2 100644 --- a/src/Paket.Core/Common/Utils.fs +++ b/src/Paket.Core/Common/Utils.fs @@ -455,7 +455,7 @@ let runDotnet workingDir arguments = let result = let p = new System.Diagnostics.Process() p.StartInfo.WorkingDirectory <- workingDir - p.StartInfo.FileName <- "dotnet" + p.StartInfo.FileName <- ProcessHelper.dotnetExe p.StartInfo.Arguments <- arguments p.Start() |> ignore p.WaitForExit()