简体   繁体   中英

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). The build prelaunch task works, but running the application doesn't work, without any error 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#. This gives me a Program.fs with this content:

// 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:

<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:

// 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:

// 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. I don't see the expected output Hello world from F#, neither in the Debug Console nor in the integrated terminal. Despite "stopAtEntry": true in the launch.json and setting breakpoints, it doesn't stop anywhere, it just seems to run through without any output. The specified "program": "${workspaceFolder}/bin/Debug/net5.0/test.dll" exists, it is built in the prelaunch build. 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
  2. Install the F# Ionide Plugin
  3. Restart VS Code
  4. Press Control (or Command on MAC) + P to bring up command pallet, type > F#
  5. Select "Change Workspace of Solution", and select the location of your code.

在此处输入图像描述

  1. Magic

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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