There are several options to define the assembly information of an .NET Core app in F#:
.fsproj file
Directory.Build.props file
When running dotnet build or dotnet publish: -p:Version=a.b.c.d
The information of the .fsproj file seems to have priority over Directory.Build.props file. You can place the Directory.Build.props file in the project folder or the solution folder.
The F5 button is the magic button to start debugging. However, if you start debugging the first time, you need to set up VisualStudio Code first. You need to setup a launch.json file to start debugging and a tasks.json file to first run the process.
Setup
Press F5
Select .NET Core
VS Code generates the launch.json file in the .vscode folder and opens it.
Edit the launch.json file
Insert the configuration entry within the selected square brackets of the ‘configuration’ section
Press Ctrl + Space Bar
Select .NET: Launch .NET Core Console App
Enter the path to the application .dll file in the program attribute: "${workspaceFolder}/src/MailBoxTransformer/bin/Debug/netcoreapp3.1/MailBoxTransformer.dll"
The path differs from the original template because the project is within the src sub-folder.
Press F5 again
VS Code now complains that it does not find the build task defined in the preLaunchTask attribute of the launch.json file
Select Configure Task
Select Create tasks.json file from template
Choose the .NET Core Executes .NET core build command template
VS Code generates the tasks.json file in the .vscode folder and opens it.
Edit the tasks.json file
If the .fsproj file is not in the main folder
Insert the path of the directory containing the .fsproj file as an additional argument for dotnet build.
"${workspaceFolder}/src/MailBoxTransformer",
To see the logs of the build task in the console (optional):
Change the presentation attribute in the tasks.json file from "silent" to "always"
Press F5 again
VS Code runs
The dotnet build process
The app
Add the launch.json and the tasks.json files located in the .vscode folder to your source control system (e.g. git).
You are now able to start the build process and the app itself from within VS Code. Now you can set break points and debug your app. I have included the complete launch.json and the tasks.json files below. Have fun!
launch.json
Located in the .vscode folder
{
// 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}/src/MailBoxTransformer/bin/Debug/netcoreapp3.1/MailBoxTransformer.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
tasks.json
Located in the .vscode folder
{
// 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",
"${workspaceFolder}/src/MailBoxTransformer",
// 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"
}
]
}
The easy way: Move first to the folder with the .fsproj file and then use dotnet run without any arguments:
cd src/MyConsoleApp
dotnet run
If you want to start the app from a location different than the one containing the .fsproj file, you need to enter the argument --project with the path to the .fsproj file.
dotnet run --project src/MyConsoleApp/MyConsoleApp.fsproj
Lately, I wanted to code some F# scripts. I started up Visual Studio Code on my MacBook and created an fsx file. Then I noticed that intellisense was not working anymore despite active code highlighting. That was the start for a long journey. I ended up on installing (again):
Intellisense was now working in F# projects and somehow/sometimes in fsx files within the context of an F# project. Then I tried it out in a stand-alone fsx file. Intellisense was not working again… Then I found some notes about the ‘FSharp.useSdkScripts’ option of the ionide-fsharp extension of Visual Studio Code. I activated the setting:
What a wonder, intellisense is working for F# fsx script files! With this setting enabled, I am no longer working with mono but with the .NET Core version of fsi (FSharp Interactive). With that, I think I don’t actually need mono.