Skip to content

Commit

Permalink
Paket.Core: honor DOTNET_ROOT env var [note: UNTESTED, DO NOT MERGE yet]
Browse files Browse the repository at this point in the history
Fixes #4141
  • Loading branch information
knocte committed Apr 12, 2022
1 parent 527c5f8 commit 828443e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/Paket.Core/Common/ProcessHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/Common/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 828443e

Please sign in to comment.