在Visual Studio中运行F#脚本。

huangapple go评论48阅读模式
英文:

Run F# script in Visual Studio

问题

以下是您要翻译的内容:

"I've been looking into running some F# scripts to automate some things. But I can't seem to be able to find a way to run the scripts. I've to an F# file.

Test.fsx

let helloWolrd = "Hello World"

printfn $"{{helloWolrd}}"

I know I can run it by selecting and running it with Alt+Enter but this just seems unpractical. How can I run an entire F# file in Visual Studio? Not by selecting the part I want to run."

英文:

I've been looking into running some F# scripts to automate some things. But I can't seem to be able to find a way to run the scripts. I've to an F# file.

Test.fsx

let helloWolrd = "Hello World"

printfn $"{helloWolrd}"

I know I can run it by selecting and running it with Alt+Enter but this just seems unpractical. How can I run an entire F# file in Visual Studio? Not by selecting the part I want to run.

答案1

得分: 1

你可以使用 Alt + Enter 键盘组合在 Visual Studio 中突出显示要发送的 F# 文件的个别代码片段,就像你指出的那样。在 VS Code 中也适用相同的方法。

你可以在命令行中使用 dotnet fsi script.fsx 运行整个脚本。这可以在 Visual Studio 中的 Developer PowerShell 或其他 CLI 中执行。

英文:

As you noted you can send individual snippets of F# files to F# Interactive by highlighting the lines you wish to send using Alt + Enter keyboard combination in Visual Studio. The same works with VS Code.

You can run entire scripts using dotnet fsi script.fsx from the command line. This works from Developer PowerShell within VS or other CLIs.

答案2

得分: 1

以下是翻译好的部分:

我想要做同样的事情,以便编写我在项目中使用的通用工具脚本。

我想要右键单击脚本,然后让VS执行它。

所以前往
工具 -> 外部工具

"添加"

我做了(显然不用引号)

标题 <- "FSI"

命令 <- "cmd.exe"

参数 <- "/c dotnet.exe fsi $(ItemPath)"

初始目录 <- "$(ItemDir)"

使用输出窗口 <- 是的

现在我可以右键单击项目并运行它。

(奇怪的是,我认为以前我做过类似的事情,但那时更复杂...但这似乎更容易 - 也许MS已经简化了它)

英文:

I wanted to do the same thing, in order to write publish scripts of general utilities i use in my projects.

I wanted to right click on the script and get VS to execute it.

so go to
Tools -> External tools

"Add"

I did (obviously without the quotes)

Title <- "FSI"

Command <- "cmd.exe"

Arguments <- "/c dotnet.exe fsi $(ItemPath)"

Initial directory <- "$(ItemDir)"

Use Output window <- Yes

Now I can right click on the item and run it.

(strangely I think ive done something like this before and it was much more complex...but this seems much easier - maybe MS has made it simpler)

huangapple
  • 本文由 发表于 2023年2月18日 23:58:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定