2. Setting Up the Development Environment
In 2008, we installed Visual C# 2008 Express, which included the .NET 3.5 framework, the SQL Compact Server DBMS, and the MSDN documentation, and then created projects using graphical wizards. Today, the development environment consists of two independent components:
- the .NET SDK (“Software Development Kit”): the compiler, the runtime platform, the libraries, and the [dotnet] command, which allows you to do everything from the command line (create, compile, run, test, and publish a program);
- an editor or a IDE (integrated development environment): [VS Code] with the [C# Dev Kit] extension, or [Visual Studio 2026], or [JetBrains Rider]. The editor is based on SDK.
This document uses the [dotnet] command for all operations: it works the same way on Windows, Linux, and macOS, regardless of the editor chosen.
2.1. .NET 10 SDK
2.1.1. Installation
.NET 10 SDK can be downloaded from https://dotnet.microsoft.com/download/dotnet/10.0. On Windows, you can also install it from a terminal (PowerShell or command prompt) using the [winget] package manager:
You must select SDK (which contains everything) and not just the “runtime” (which only allows you to run pre-compiled programs). On Linux, SDK is available in the repositories of major distributions (for example, [sudo apt install dotnet-sdk-10.0] on Ubuntu; depending on the distribution version, you may need to add the repository specified in Microsoft’s installation documentation beforehand).
After installation, open a new terminal to verify that the [dotnet] command is available and displays the version of SDK:
The command [dotnet --list-sdks] lists the installed SDK versions (multiple versions can coexist):
The exact version (in this case, [10.0.112]) depends on the installation date: Microsoft releases a hotfix update every month. All versions of SDK and 10.0.x are suitable for this document. The [dotnet --info] command provides more detailed information (operating system, location of SDK, versions of installed runtime platforms).
2.1.2. The dotnet command
The [dotnet] command includes many subcommands. Here are the ones we’ll use:
Command | Role |
[dotnet run file.cs] | compiles and runs a single-file application |
[dotnet new console -n Name] | creates a console project in the [Name] folder (other templates: [classlib], [mstest], [web]…) |
[dotnet build] | compiles the project in the current folder |
[dotnet run] | compiles (if necessary) and runs the project in the current folder |
[dotnet test] | runs the unit tests (Chapter 6) |
[dotnet new sln] | creates a solution (a file that groups multiple projects) |
[dotnet sln add Project] | adds a project to the solution |
[dotnet add package Name] | adds a library NuGet to the project (Chapters 10 and 11) |
[dotnet add reference ../Other] | adds a reference to another project (Chapter 6) |
[dotnet publish] | prepares the program for deployment |
Libraries that are not part of the platform are distributed as NuGet packages, downloaded from https://www.nuget.org and stored on the computer in the [%USERPROFILE%\.nuget\packages] folder. In 2008, we copied the DLL files for the libraries (Spring.NET, NUnit, and the MySQL connector) into a [lib] folder within the project; today, the project declares the packages it needs, and the [dotnet] command downloads them.
2.2. The editor
2.2.1. VS Code
VS Code is a free, cross-platform editor. To program in C#, you add Microsoft’s C# Dev Kit extension (go to the “Extensions” menu and search for “C# Dev Kit”), which also installs the C# extension. This provides:
- syntax highlighting, code completion, and tooltip help;
- error detection as you type;
- code navigation (F12: Go to Definition);
- a Solution Explorer (“Solution Explorer” view);
- execution and debugging (F5);
- running unit tests (the “Testing” view).
In VS Code, open the folder containing the programs (“File / Open Folder”), for example, the [csharp-oct-2026] folder with the examples from this document. The built-in terminal (“Terminal / New Terminal”) allows you to enter [dotnet] commands without leaving the editor.
2.2.2. Visual Studio 2026
On Windows, you may prefer to use Visual Studio 2026, the successor to Visual Studio 2008 used in the original course. Its Community edition is free for individuals, educational institutions, and open-source projects. Install it from https://visualstudio.microsoft.com by selecting the “.NET Desktop Development” workload (and “ASP.NET and web development” for Chapter 13). Visual Studio opens the [.slnx] solutions and [.csproj] projects from the examples directly (“File / Open / Project/Solution”), and runs them using [Ctrl-F5] (without debugging) or [F5] (with debugging), just as in 2008.
A third option is JetBrains Rider, which is free for non-commercial use.
In the rest of this document, the steps are described using the [dotnet] command, which produces the same results regardless of the editor.
2.3. A First Program: A Single-File Application
2.3.1. The program
Starting with .NET 10, a C# program can be a single [.cs] file, without a project file. This is called a "file-based app." Let's create the following [hello.cs] file:
and run it:
Comments:
- line 1: a comment. Everything following [//] until the end of the line is ignored by the compiler;
- line 2: the program’s only statement: it prints a line of text to the screen. The program has neither a class nor a method named [Main], unlike its 2008 counterpart; we’ll see in Chapter 3 that the compiler generates them itself;
- The [dotnet run hello.cs] command compiles the program and then executes it. The first execution takes a few seconds; subsequent executions are almost immediate as long as the file remains unchanged, since the compilation result is stored in a cache.
Single-file applications are suitable for small programs, and we’ll use them for most of the examples. A few directives, placed at the beginning of the file, allow you to create them without a project file:
- the directive [#:package] adds a NuGet library (Chapter 10);
- the directive [#:property] sets a compilation property (Chapter 5);
- the [#:sdk] directive selects a different SDK, such as the one for web applications (Chapter 12).
On Windows, if [.cs] files are saved as UTF-8 (which is the default in VS Code), accented characters display correctly in the terminal.
2.3.2. Converting a Single-File Application into a Project
When a single-file application grows (multiple files, tests, references to other projects), it is converted into a project:
The command creates a folder named [hello] containing a copy of the program and a project file named [hello.csproj]:
The project file inherits the default properties of single-file applications (for example, [PublishAot], which prepares for early compilation into native code). You can remove any that are not needed. We will now look at the projects in more detail.
2.4. A console project
2.4.1. Creating the Project
A project is a folder containing a project file ([.csproj]) and source files. It is created using the command [dotnet new] followed by the name of a template (in this case, [console], a console application):
The command created a folder named [FirstProgram] containing two files. The project file [FirstProgram.csproj] is as follows:
- Line 1: The project uses SDK [Microsoft.NET.Sdk], the one for console applications and libraries;
- line 4: the project produces an executable ([Exe]) rather than a library;
- line 5: the target platform is .NET 10 ([net10.0]);
- line 6: the most common namespaces ([System], [System.IO], [System.Linq]…) are automatically imported into all files (Chapter 3);
- line 7: the compiler checks for the use of null references and issues warnings about potential errors (Chapters 3 and 4).
The 2008 file described each source file in the project, library references, and Debug/Release configurations in about a hundred lines. The current project file contains only the settings that differ from the defaults: all [.cs] files in the folder are part of the project.
We replace the contents of the generated [Program.cs] file with the following:
2.4.2. Compilation and Execution
The command [dotnet build], entered in the project folder, compiles the project:
- Line 2: The command begins by restoring the project, which means downloading the NuGet packages it depends on (there are none here);
- Line 4: The result of the compilation is a DLL and [FirstProgram.dll] file placed in the project’s [bin/Debug/net10.0] folder. On Windows, the displayed path is a Windows path ([bin\Debug\net10.0\FirstProgram.dll]).
The [bin/Debug/net10.0] folder then contains the following files:
- [FirstProgram.dll] contains the compiled code (in intermediate code IL);
- [FirstProgram] (on Windows, [FirstProgram.exe]) is a small launcher that starts the .NET platform and causes it to execute the DLL;
- [FirstProgram.pdb] contains the information used by the debugger;
- the two [.json] files describe the program’s dependencies and the version of .NET required to run it.
You can run the launcher directly:
However, the [dotnet run] command is most commonly used; it compiles the project if necessary and then runs it:
As in 2008, there are two build configurations: Debug (default, with debug information) and Release (optimized, for production), selected using the option [-c Release]: [dotnet build -c Release] generates the program in the [bin/Release/net10.0] folder. The [obj] folder contains intermediate compilation files. The [bin] and [obj] folders can be safely deleted: they are recreated during the next compilation.
2.5. A Solution with Multiple Projects
2.5.1. Creating the solution
A solution groups multiple projects together. It allows you to open them together in the editor and compile them together. Let’s create a solution in the folder containing the [FirstProgram] project:
then let’s add the project to it:
Let’s add a second project, [TwoHands], whose contents we’ll look at below:
The command [dotnet sln list] lists the projects in the solution:
The solution file [02-installation.slnx] is as follows:
This is a very simple XML file. Since .NET 10, this has been the default format for solutions ([.slnx]). The old [.sln] format, used in Visual Studio 2008, was much more verbose; it is still found in existing projects, and the [dotnet new sln --format sln] command can still be used to create it.
In the solution folder, the command [dotnet build] compiles all projects in the solution. To run a specific project, navigate to its folder and type [dotnet run], or use the [--project] option: [dotnet run --project FirstProgram].
2.5.2. A Project with Multiple Main Methods
The 2008 course demonstrated that a project can contain multiple classes, each with a static method named [Main], and that you must specify which one to execute. This is still possible. The project [TwoHands] contains two classes. The class [P1]:
and the [P2] class:
If you compile the project without taking any further precautions, you’ll get an error:
The compiler does not know which method, [Main], is the program’s entry point. We specify this in the project file using the [StartupObject] property:
- Line 9: The method [Main] that was executed belongs to the class [TwoHands.P2] (the full class name, including the namespace).
Results:
With high-level statements (Chapter 3), the question no longer arises: a single file in a project can contain them, and that file serves as the entry point.
2.6. Examples in this document
To run the examples in this document:
- download the [csharp-oct-2026] folder (link at the beginning of the document);
- open it in VS Code (“File / Open Folder”) or, for a specific chapter, open the chapter’s solution ([.slnx]) in Visual Studio;
- in a terminal located in a chapter’s folder, run a single-file application using [dotnet run name.cs], or a project using [dotnet run] in the project folder.
Chapters 10 and 11 use a MySQL database; the installation of MySQL with [Laragon] is described in the appendix.