How to set up F# development in visual studio code

I’ve just realised that I’ve never done this before.

Here’s what I did just now to debug a .NET Core console F# app - you should be able to adjust as necessary.


Pre-requisites:

  • In VS Code - I have the Ionide F# and the Microsoft C# extension.
  • I’m using .NET Core 3.1 SDK.

To get started ran the following on the command line:

> cd AProject
> dotnet new console -lang f#
> code .

Once in VS Code I just pressed F5, and when prompted for an “Environment” I selected “.NET Core”

This opened me a launch.json like so:

{
    // 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": []
}

At the bottom right of the editor I clicked “Add Configuration”:

image
and selected “.NET: Launch .NET Core Console App”

I then had to update the “program” to point to the framework and assembly name. In my case:

//Changing
"program": "${workspaceFolder}/bin/Debug/<target-framework>/<project-name.dll>",
//to
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/AProject.dll",

I then pressed F5 again and when prompted about a missing “build” task I clicked “Configure Task”:

image
Then I selected “Create tasks.json file from template”, then selected the “.NET Core” template.

Now when I press F5 it launches the app with the debugger attached:


As I said, at the start, I’d not done this before, usually I’m just writing scripts in F# and using the REPL to run them. Or I just use dotnet run from the terminal, one of the things I like about F# and functional programming is that I spend a lot less time debugging code than I do with C#.

5 Likes