Can I install/reference packages from within an fsx file?
The Ionide plugins for VsCode and Atom have the functionality you're looking for
VsCode Instructions
Use the command palette to install the Ionide extensions ionide-fsharp and ionide-paket
You'll need to add your F# installation to your PATH
(on windows Rapid Enivornment Editor is my goto for PATH
editing)
For F# 4.0 add C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0
Open the work folder that will hold your .fsx
files
Executing paket commands through the command palette will be your primary interface for working with nuget packages
make a new .fsx
file, (I recommend using the Advanced New File extension over the standard VsCode method)
The first step is to run paket init
which is necessary to use paket to manage your packages
If you click the open
button on the notification popups you can view the the output from paket in a side panel
After using the add nuget package
command and entering extcore
for the package you should see the work tree
updated to
Then all you need to do is reference the package in the script and you'll get the auto-completion you're looking for
As of F# 5.0 you can now use the #r "nuget: Package"
(ref):
#r "nuget: Newtonsoft.Json"
// Optionally, specify a version explicitly
// #r "nuget: Newtonsoft.Json,11.0.1"
open Newtonsoft.Json
let o = {| X = 2; Y = "Hello" |}
printfn "%s" (JsonConvert.SerializeObject o)