#package directive to import NuGet packages in F# interactive
It would be quite useful for F# interactive to support a #package directive to allow NuGet packages to be downloaded from within the REPL. I think it would be best if this directive simply downloaded the package, unpacked it, and automatically included (#I) the correct folder based on the framework version F# interactive is running under (e.g., net45). If a package doesn't include assemblies for the specific framework version F# interactive is using, we'd automatically include the folder for the latest framework version which is compatible; e.g., if running on .NET 4.5 and a package only includes a 'net40' folder, we'd include (#I) that folder. I believe this behavior is consistent with how NuGet currently works when referencing packages from a project, e.g., in Visual Studio.
#package should not, however, automatically reference (#r) the assemblies included in the package, in case you only want to reference some of them.
Here's a usage example:
let substr = substring "Hello World!"
printfn "Value: %O" substr;;
Gauthier Segay commented
issue on github https://github.com/Microsoft/visualfsharp/issues/56
Jared Hester commented
Instead of a specific directive what if we could define a set of preprocessors with custom behaviors in a dll and have fsi automatically reference that assembly at startup.
It would be nice if one could also easily import DLL's from projects in the current solution !
exercitus vir commented
I like that this would be independent of the package management client.
Don Syme commented
You can use the following formula to download both a package-management-client tool (paket.exe) at the start of a script and then use it to then download nuget packages:
It's really cool and close to what's needed, without building in things into F# Interactive.
Adding #nuget to F# Interactive would be a smoother experience, but also has some risks (e.g. nuget is still an evolving thing in many ways).
Greg Chernis commented
Here's a workaround: http://tobivnext.wordpress.com/2014/03/26/import-nuget-packages-to-fs-interactive/
Christoph Rüegg commented
Jon Harrop commented