gpt4 book ai didi

f# - 在 .net 5 中运行 Forms 表单 F# 脚本?

转载 作者:行者123 更新时间:2023-12-03 23:01:38 28 4
gpt4 key购买 nike

是否可以将 Windows.Forms 称为 F# 脚本?
据我所知,尝试将它们引用为 .nuget 包时会出现问题,如 here 所述。 ,具有潜在的解决方案(直接在目标机器上引用文件),描述了here .
我没有尝试查看建议的解决方案是否适用于 .net core 3.1(帖子作者使用作者使用的)。
但是,在直接引用光盘上的文件之后,我无法在 .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

关于f# - 在 .net 5 中运行 Forms 表单 F# 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65373859/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com