Skip to content

FSI nuget reference (#r) breaks the process' PATH environment variable on Linux #11729

@seanamos

Description

@seanamos

When using #r "nuget: .....", FSI appends a string to the PATH environment variable:
PATH=/usr/local/sbin:/xxxxxxx;/homepath/.nuget/packages/package/x.x.x/;

It uses the ; character as a separator, however in Linux : is the PATH env var separator.
Surprisingly, some distributions are tolerant of this (Ubuntu), others however are not (Alpine).

This has all sort of weird side effects in the FSI process/script that is running, especially if you try launch a sub process.

Repro steps

#r "nuget: Newtonsoft.Json"

System.Environment.GetEnvironmentVariables()
|> Seq.cast<System.Collections.DictionaryEntry>
|> Seq.filter (fun x -> x.Key |> string = "PATH")
|> Seq.iter (fun x -> printfn "%s:%s" (string x.Key) (string x.Value))

Expected behavior

FSI appends to PATH with the platform specific separator.

Actual behavior

PATH gets butchered.

Known workarounds

#r "nuget: Newtonsoft.Json"

// 😥
let fixedPathEnv = System.Environment.GetEnvironmentVariable("PATH").Replace(';', ':').TrimEnd(':')
System.Environment.SetEnvironmentVariable("PATH", fixedPathEnv)

System.Environment.GetEnvironmentVariables()
|> Seq.cast<System.Collections.DictionaryEntry>
|> Seq.filter (fun x -> x.Key |> string = "PATH")
|> Seq.iter (fun x -> printfn "%s:%s" (string x.Key) (string x.Value))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions