运行 在 .net 5 中形成 F# 脚本?

Running Forms forms F# script in .net 5?

是否可以将 Windows.Forms 作为 F# 脚本调用? 据我所知,如 here, with potential solution (referencing the files directly on the target machine), described here 所述,尝试将它们引用到 .nuget 包时会出现问题。 我没有尝试查看建议的解决方案是否适用于 .net core 3.1(post 作者使用了作者使用的)。 但是,在直接引用光盘上的文件之后,我无法 运行 .net 5 下的解决方案,错误类似于 “无法加载文件或程序集 'System.Drawing.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'。无法找到或加载特定文件。(0x80131621)”。

代码如下:

#r "DotnetLocation/dotnet/shared/Microsoft.WindowsDesktop.App/5.0.1/System.Windows.Forms"
#r "DotnetLocation/dotnet/shared/Microsoft.WindowsDesktop.App/5.0.1/System.Drawing"
#r "DotnetLocation/dotnet/shared/Microsoft.WindowsDesktop.App/5.0.1/System.Drawing.Common"
#r "D:/F# Examples/Chapter7Libs/Vector/bin/Debug/netcoreapp5.0/Chapter7libs"
open System.Drawing
open System.Windows.Forms
Application.EnableVisualStyles()let winSize = Size(450, 300)
let display (title: string, (c: Curve.Curve, pw: int, ph: int)) =
   let f(x,y) = Point(int(round x), ph - int(round y))
   let clst = Curve.toList c
   let ptLst = List.map f clst
   let pArr = Array.ofList ptLst    let pen = new Pen(Color.Black)
   let draw(g: Graphics) = g.DrawLines(pen, pArr)    let panel = new Panel(Dock=DockStyle.Fill)
   panel.Paint.Add(fun e -> draw(e.Graphics))    let win = new Form(Text=title, Size=winSize, AutoScroll=true, AutoScrollMinSize=Size(pw,ph))
win.Controls.Add(panel)
win.Show()

(示例来自“使用 F# 的函数式编程”,第 7 章)。 尝试将 Forms 调用包装到 dll 中并从脚本中调用它们也不起作用 - 脚本无法加载包装调用的模块(来自同一 dll 的其他模块工作正常)。

PS: 尝试编译代码时没有问题,它工作正常,我的问题只是交互式脚本。

引用 Phillip Carter 对问题的评论作为目前接受的答案。

No, it's not a supported scenario at the moment. Winforms is not just a library anymore, it is its own special kind of dependency closure that is only currently understood by msbuild when it does a build. That's why it works in a project but not in a script