简体   繁体   English

在 Linux 上的 VS 代码中设置 F# 调试

[英]Setting up F# Debugging in VS Code on Linux

I'm new to .NET and F#, and I'm trying to set up F# debugging in VS Code on Linux (NixOS to be precise, although I guess that shouldn't matter). I'm new to .NET and F#, and I'm trying to set up F# debugging in VS Code on Linux (NixOS to be precise, although I guess that shouldn't matter). The build prelaunch task works, but running the application doesn't work, without any error output.构建预启动任务有效,但运行应用程序不起作用,没有任何错误 output。

Here's how to reproduce it.这是重现它的方法。

In a directory called test, I create an F# console application by running dotnet new console -lang F#.在名为 test 的目录中,我通过运行 dotnet new console -lang F# 创建了一个 F# 控制台应用程序。 This gives me a Program.fs with this content:这给了我一个包含以下内容的 Program.fs:

// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp

open System

// Define a function to construct a message to print
let from whom =
sprintf "from %s" whom

[<EntryPoint>]
let main argv =
    let message = from "F#" // Call the function
    printfn "Hello world %s" message
    0 // return an integer exit code

and a test.fsproj with this content:以及包含以下内容的 test.fsproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

</Project>

I create a (VS Code-specific) launch.json with the following content:我创建了一个(特定于 VS 代码的)launch.json,其内容如下:

// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/bin/Debug/net5.0/test.dll",
        "args": [],
        "cwd": "${workspaceFolder}",
        "stopAtEntry": true,
        "console": "internalConsole"
    }
]

and a (VS Code-specific) tasks.json with this content:和一个(VS Code-specific)tasks.json,内容如下:

// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "command": "dotnet",
        "type": "shell",
        "args": [
            "build",
            // Ask dotnet build to generate full paths for file names.
            "/property:GenerateFullPaths=true",
            // Do not generate summary otherwise it leads to duplicate errors in Problems panel
            "/consoleloggerparameters:NoSummary"
        ],
        "group": "build",
        "presentation": {
            "reveal": "always"
        },
        "problemMatcher": "$msCompile"
    }
]

When I hit F5, it builds, but the application doesn't seem to run.当我按 F5 时,它会构建,但应用程序似乎没有运行。 I don't see the expected output Hello world from F#, neither in the Debug Console nor in the integrated terminal.我在调试控制台和集成终端中都没有看到来自 F# 的预期 output Hello world。 Despite "stopAtEntry": true in the launch.json and setting breakpoints, it doesn't stop anywhere, it just seems to run through without any output.尽管"stopAtEntry": true在 launch.json 中设置了断点,但它不会在任何地方停止,它似乎只是在没有任何 output 的情况下运行。 The specified "program": "${workspaceFolder}/bin/Debug/net5.0/test.dll" exists, it is built in the prelaunch build.指定的"program": "${workspaceFolder}/bin/Debug/net5.0/test.dll"存在,它是在预启动构建中构建的。 Actually, I can enter any non-sense path there and see just the same behavior (no error output).实际上,我可以在那里输入任何无意义的路径并看到相同的行为(没有错误输出)。

What am I doing wrong?我究竟做错了什么?

What I did to get things working is to:我做的事情是:

  1. Install the Omnisharp (C#) Plugin安装 Omnisharp (C#) 插件
  2. Install the F# Ionide Plugin安装 F# Ionide 插件
  3. Restart VS Code重启 VS 代码
  4. Press Control (or Command on MAC) + P to bring up command pallet, type > F#按 Control(或 MAC 上的 Command)+ P 调出命令托盘,输入> F#
  5. Select "Change Workspace of Solution", and select the location of your code. Select “更改解决方案的工作区”,以及 select 代码的位置。

在此处输入图像描述

  1. Magic魔法

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM