How to use nuget install package for F# script without a solution?
Since late 2019, this is now natively supported:
#r "nuget: Suave"
#r "nuget: FSharp.Data"
#r "nuget: FSharp.Charting"
Original answer:
There is a fun hack you can do that is documented on the suave.io web site, which downloads Paket and then uses it to download packages - and all of this in a few lines in a script file:
// Step 0. Boilerplate to get the paket.exe tool
open System
open System.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
let url = "https://github.com/fsprojects/Paket/releases/download/0.31.5/paket.exe"
use wc = new Net.WebClient()
let tmp = Path.GetTempFileName()
wc.DownloadFile(url, tmp)
File.Move(tmp,Path.GetFileName url)
// Step 1. Resolve and install the packages
#r "paket.exe"
Paket.Dependencies.Install """
source https://nuget.org/api/v2
nuget Suave
nuget FSharp.Data
nuget FSharp.Charting
""";;
It is a bit long for my taste, but it lets you do everything without leaving a script file and F# Interactive.
The new out-of-the-box way to do this is simply add this in your .fsx script:
#r "nuget: FSharp.Data, Version=3.3.3"
(The PR that implemented this, for reference; and the release where this is unveiled.)
OLD ANSWER:
For Linux users out there, if your distro is Debian-based (tested with Ubuntu 16.04), you could, inside your F# script, do:
- Install the
nuget
package if it's not installed already (usesudo apt install nuget
). - Do
nuget install FSharp.Data -Version 2.3.2
. - Load the DLL via an
#r
line (e.g.#r "FSharp.Data.2.3.2/lib/net40/FSharp.Data.dll
).
This way you don't need to download .exe files from some web server, which feels totally insecure.
PS: Beware, you would still be trusting the library (binary) received from (Microsoft's) Nuget server though.