F# projects in dotnet
In this post I am to introduce the dotnet environment from an F# point of view. However, I hope this will be generally useful for dotnet…
Hello World in F
In this post I introduce creating and running an F# Hello World project.
I presume you have installed
on your machine. I will explain
- how to create a solution and a project file and how to link them
- how to run the Hello World program from the command line
- how to run the Hello World program from Visual Studio Code
As usual, the Hello World program is easy, to configure its running environment is not so much.
In theory, you could use Visual Studio Code for creating projects and solutions but the sure method is to use the dotnet command line.
First, navigate yourself to a directory you like to use for program code, create a hello directory and go into it:
>mkdir hello
>cd hello
hello>
Our first dotnet specific task is to create the topmost entity in the dotnet world: a solution file. They have .sln extension but dotnet automatically add this:
hello>dotnet new sln --name hello
The template "Solution File" was created successfully.
hello>dir
Volume in drive C is Rendszer
Volume Serial Number is 3A92-4546
Directory of C:\Users\gbuday\hello
2020. 10. 07. 13:27 <DIR> .
2020. 10. 07. 13:27 <DIR> ..
2020. 10. 07. 13:27 540 hello.sln
1 File(s) 540 bytes
2 Dir(s) 30 198 591 488 bytes free
So you have it! If you open it with notepad, you see something similar to
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This is not for human consumption, be satisfied with the fact that you have a solution file.
The next step is to create a project file for a console application:
hello>dotnet new console -lang F# -o HelloWorld
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on HelloWorld\HelloWorld.fsproj...
Determining projects to restore...
Restored C:\Users\gbuday\hello\HelloWorld\HelloWorld.fsproj (in 477 ms).
Restore succeeded.
hello>cd HelloWorld
HelloWorld>
F# helps to create a Hello World program by copying the necessary code into a new project:
HelloWorld>dir
Volume in drive C is Rendszer
Volume Serial Number is 3A92-4546
Directory of C:\Users\gbuday\hello\HelloWorld
2020. 10. 07. 13:38 <DIR> .
2020. 10. 07. 13:38 <DIR> ..
2020. 10. 07. 13:38 252 HelloWorld.fsproj
2020. 10. 07. 13:38 <DIR> obj
2020. 10. 07. 13:38 172 Program.fs
2 File(s) 424 bytes
3 Dir(s) 30 161 448 960 bytes free
where Program.fs contains
// Learn more about F# at http://fsharp.org
open System
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code
This opens the System module that contains the functionality used in this short program. Function main is an entry point that should be explicitly stated in F#. In C, this is harwired to be the function called main. Here it can have other name but for readability it uses the main convention. It has a type
string array -> int
and the console environment passes the command line parameters as a string list and the return value of the function will be passed back to the operating system.
The very essence of the Hello World program is the printfn function call with the obvious string parameter.
Now you can run it:
HelloWorld>dotnet run
Hello World from F#!
Success! Success? We should check it:
HelloWorld>echo %errorlevel%
0
This Windows CMD variable contains the return value of the last executed command. In bash you would use
$ echo $?
0
For the curious, you can change the return value in Program.fs and see what happens with the above command.
So we created a solution and a project and ran the famous Hello World program. What’s next? Let’s see how can we use these in VS Code.
We are to connect the project into the solution. Step back to the solution’s hello directory and issue the necessary command:
HelloWorld>cd ..
hello>dotnet sln add HelloWorld
Project `HelloWorld\HelloWorld.fsproj` added to the solution.
So we named the project by its containing folder, dotnet automatically finds the project file inside it. Now in the hello.sln file a new line appears:
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HelloWorld", "HelloWorld\HelloWorld.fsproj", "{27753E6C-20D3-4EC3-8DE9-481574A03301}"
Start VS Code and in the File menu, choose Open Folder and point to our hello directory above. The EXPLORER will show your files:

The Hello World solution in VS Code Explorer
You see your solution file hello.sln, your project directory HelloWorld, your program file Program.fs and various generated files and directories.
Our next task is to run the program inside VS Code. Click on Program.fs and push F5, that is, debugging your program. Itt will not work for the first but will open launch.json and offer Add Configuration. Click on it, it will give you some possibilities, choose
{} .NET: Launch .NET Core Console App
In launch.json there will be a line
"program": "${workspaceFolder}/bin/Debug/<target-framework>/<project-name.dll>"
that you should edit to link your executable to the executing environment.
You can learn your target framework from your project file HelloWorld.fsproj:
<TargetFramework>netcoreapp3.1</TargetFramework>
Using that and the directory structure we created above write this into launch.json:
"program": "${workspaceFolder}/HelloWorld/bin/Debug/netcoreapp3.1/HelloWorld.dll"
Upon hitting F5 one gets an error dialog box:
Could not find the task 'build'.
There, choose
Configure Task
and then
Create tasks.json file from template
and last the
.NET Core
template. Now, going back to the Program.fs window, pushing F5 you get this in the DEBUG CONSOLE:
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Users\gbuday\hello\HelloWorld\bin\Debug\netcoreapp3.1\HelloWorld.dll'. Symbols loaded.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Users\gbuday\hello\HelloWorld\bin\Debug\netcoreapp3.1\FSharp.Core.dll'. Symbols loaded.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\netstandard.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Runtime.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Console.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Text.Encoding.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Collections.Concurrent.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Hello World from F#!
The program '[11292] HelloWorld.dll' has exited with code 0 (0x0).
So you are now ready to run F# programs from the command line or from Visual Studio Code.
메타데이터
- post_id
- 6ae59d347a9a
- slug
- f-projects-in-dotnet-6ae59d347a9a
- url
- https://medium.com/@buday.gergely.istvan/f-projects-in-dotnet-6ae59d347a9a
- canonical_url
- https://medium.com/@buday.gergely.istvan/f-projects-in-dotnet-6ae59d347a9a
- author_url
- https://medium.com/@buday.gergely.istvan
- status
- ok
- fetched_at
- 2026-07-28 19:00:09