I thought I'd share some simple steps you can follow if you wan't to build, run and debug an F# program on OSX using dotnet core 2.0. I guess these steps would also work if you're running Linux, with some minor modifications.
-
Install dotnet sdk for OSX: https://www.microsoft.com/net/learn/get-started/macos
-
Install Visual Studio Code for OSX: https://code.visualstudio.com/
-
Install C# (yes, C#) extension for OSX: https://code.visualstudio.com/docs/languages/csharp
-
Create a new console application project using dotnet cli:
dotnet new console -lang F# -n HelloWorld -
Build your project
cd HelloWorld,dotnet restore,dotnet buildDid it build? Hope so... -
Run your project:
dotnet runShould output "Hello World from F#!" -
Open your project in Visual Studio Code:
- Start Visual Studio Code
- Select your project directory:
File > Open... >
-
Setup build task:
- From the top menu, select
Tasks > Run build task... - Click
No build task to run found. Configure Tasks... - Click
Create tasks.json file from template - Select
.NET Corefrom the options displayed - If you want, you can add a task for nuget packet restore. Example in
tasks.jsonbelow
- From the top menu, select
-
Setup lunch.json for debugging:
- From the top menu, select
Debug > Start Debugging - Select
.NET Corefrom the options displayed - A new file
launch.jsonwill be created 1. Point theprogramsetting to your debug output directory. Example inlaunch.jsonbelow - Save and close the file
- From the top menu, select
-
Debug your console application:
- Open
Program.fs - Place a new breakpoint in your code. If you didn't touch the file created by the template upon installation, line 7 should be a good example. Place your cursor on line 7 and from menu select
Debug > Toggle BreakpointA red dot should now appear in the margin to the left - From the top menu, select
Debug > Start Debuggingor pressF5 - If everything worked out your debugger should now be stopped at your breakpoint. Hit
F5to continue. - You should now see your "Hello World from F#!" output in the Debug Console
- Open
To get the most out of F# in Visual Studio Code, install extension Ionide-fsharp. This should give you things like IntelliSense and highlighted errors and stuff like that.
I hope this helped! Take care :)
Thank you so very much for sharing this!