How to use nuget installation package for F # script without solution?

I am trying to write a F # script file. Therefore, I use Visual Studio "File-> New-> Files-> F # script File" to create a new fsx file. Now I want to add a link to FSharpData by opening the package manager console and type

Install-Package FSharp.Data 

However, I got the following error. Does a solution always need to be created even for an F # script file?

  Install-Package: The current environment doesn't have a solution open.
 At line: 1 char: 1
 + Install-Package FSharp.Data
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo: InvalidOperation: (:) [Install-Package], InvalidOperationException
     + FullyQualifiedErrorId: NuGetNoActiveSolution, NuGet.PowerShell.Commands.InstallPackageCommand
+5
source share
3 answers

There is a funny hack that you can register on the suave.io website that Paket downloads and then uses it to download packages - all in a few lines in the 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 """;; 

This is a little long for my taste, but it allows you to do everything without leaving the script file and F # Interactive.

+6
source

You can use nuget.exe directly rather than using the Visual Studio package manager. This means that you can use any editor, not just Visual Studio.

As an example, copy the NuGet.exe file from any other project to the same folder as your .fsx, and then run "Nuget.exe install package-name"

eg.

 NuGet.exe install FSharp.Data 

Nuget will create the FSharp.Data folder with the latest version. Then just add #r to the added assembly and all the dependencies.

+4
source

For Linux users, if your Debian distribution is based (tested with Ubuntu 16.04), you can execute in your F # script:

  • Install the nuget package if it is not already installed (use sudo apt install nuget ).
  • Make nuget install FSharp.Data -Version 2.3.2 .
  • Download the DLL via the line #r (for example, #r "FSharp.Data.2.3.2/lib/net40/FSharp.Data.dll ).

Thus, you do not need to download .exe files from any web server that feels absolutely unsafe.

PS: Beware, you will still trust the library (binary) received from the Nuget server (Microsoft), though.

0
source

All Articles