Can I install/reference packages from within an fsx file?

倾然丶 夕夏残阳落幕 提交于 2020-02-19 16:00:51

问题


I'm trying to find a simple solution that isn't so much manual work to reference packages. inside a .fsx file.

  • LinqPad 4 lets me simply add nuget packages
    • no intellisense or autocompletion
    • deletes package after download for certain types of packages (templatus for example)
  • LinqPad 5 beta lets me add nuget packages
    • deletes package after download for certain types of packages (templatus for example)
    • with frequent failures (intellisense and compilation)
  • VS2015 doesn't let you download/install packages for an fsx file (only into projects)
  • VSCode doesn't let you download/install nuget or paket packages for an fsx file.

So I wind up having to use .fsx in VS2015, while using linqpad to get packages downloaded (which still fails for packages like templatus where it downloads an exe not a dll). Then I have I can reference them as

#I @"..\LINQPad\NuGet.FW46\FParsec\FParsec.1.0.2\lib\net40-client\" // references AppData\local\ ...  since . is %localappdata%\TEMP
  • doesn't match up with the relative pathing for intellisense/autocompletion engine in VSCode so I can't remove VS from the equation.
  • doesn't work outside of a machine that already has that package in that location
  • wind up doing a bunch of code that doesn't span .fsx files very well and has to be worked out per package reference

I don't want to create a project. I have a ton of individual scripts that are to be individually maintained and usable by others on-demand.

Is there an IDE (or fix/extension for one of these mentioned) that will give me intellisense, autocomplete, and package management for F# .fsx files that can work easily from user to user, machine to machine?


回答1:


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 extcorefor 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



来源:https://stackoverflow.com/questions/34813796/can-i-install-reference-packages-from-within-an-fsx-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!