How to set up F# development in visual studio code

Hi All.

I am a C# developer and I am currently trying to pick up F# which I see a lots of potential in it. However, I am not able to set up the F# development environment in Visual Studio Code as in I am not sure which configuration should i add in the launch.json

any help is appreciated.

Best regards,
Helicon

2 Likes

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#.

4 Likes

Hi Dave,

Thanks for such detail guide! I finally managed to get it running in visual studio code!

Really appreciate your input.

Best regards,
Helicon

1 Like

We also created a short video series here which might be useful for you! https://www.youtube.com/playlist?list=PLlzAi3ycg2x0TScJb7czq7-4LrQoyTB0I

It’s a little out of date now because netcore now supports FSI but otherwise it should be useful!