0

I am confused about the difference between referencing fsharp.charting.gtk in interactive and compile mode. The following code

#load "FSharp.Charting.Gtk.2.1.0/lib/net45/FSharp.Charting.Gtk.fsx"
open FSharp.Charting;;         
Chart.Line [ for x in 0 .. 10 -> x, x*x ];;

produces a graph as expected in interactive mode with fsharpi, and I can compile it without errors using fsharpc but running it with mono gives the error:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'

I realize that '#load' is for interactive mode, but I have not been able to discover its correct replacement for compile mode. I'm on osx v. 11.5.2 with an Apple M1 chip. Any help would be much appreciated. Thanks.

4

1 回答 1

0

#load是 F# 仅交互指令。它允许您将另一个 F# 脚本“加载”到当前交互式会话中。您似乎已经发现 paket 可以为您生成这些加载脚本,它允许您将包包含到交互式会话中。*

要在已编译的程序集中包含一个包,您需要将其添加为对您的项目 (.fsproj) 的引用。由于您使用的是 paket,因此您可以像这样添加它:dotnet paket add FSharp.Charting.Gtk. 您不需要#load编译代码中的指令。

有关详细信息,请查看包的 NuGet 页面,该页面告诉您将包添加到项目的各种方法。

* 现在使用 F# 5,您实际上不再需要 FSI 中的那些 paket 加载脚本;您现在可以这样做:(#r: "nuget: FSharp.Charting.Gtk请参阅如何在没有解决方案的情况下为 F# 脚本使用 nuget 安装包?)。

于 2021-09-24T16:51:52.023 回答