To write, compile, and run C# programs you need two things: the .NET SDK (the tools that
compile and run your code) and an editor or IDE where you can write that code comfortably.
In this lesson we'll install and configure both, learn the basic commands of the dotnet
command-line tool, and confirm that everything works by creating and running a test project.
This is the essential step before we can move on, in the next lesson, to BiblioTech's first
real program.
Contents
- Installing the .NET SDK
- Choosing an editor or IDE
- The structure of a console project created with
dotnet new console - Basic dotnet CLI commands
- Verifying that the environment works
Installing the .NET SDK
The .NET SDK (Software Development Kit) is the set of tools needed to build and run .NET applications, including programs written in C#. It includes:
- The C# compiler (which translates your source code into intermediate language, IL).
- The .NET runtime (the engine that runs that code, including the garbage collector and the JIT compiler mentioned in the previous lesson).
- The dotnet CLI, a command-line tool for creating, building, running, and managing projects.
Steps to install the SDK
- Visit the official .NET downloads page (
dotnet.microsoft.com/download). - Download the latest LTS (Long Term Support) version. LTS versions receive updates and support for a longer period, making them the safest choice for learning and for real projects.
- Run the installer for your operating system (Windows, macOS, or Linux). The process is the usual one: next, accept, install.
- Restart your terminal (or the computer itself, if the installer tells you to) so the system changes take effect.
Checking the installation
Once installed, open a terminal (Command Prompt, PowerShell, or a Linux/macOS terminal) and run:
Note: although this command isn't C# code, throughout this course we'll show terminal commands in code blocks so you can visually tell them apart from regular text.
If the installation went well, you'll see a version number such as 8.0.100 or similar. If
instead you get a "command not found" error, check that the installation completed correctly
and that the terminal was restarted.
You can also request more detailed information about the installed environment:
This command shows the SDK version, the installed runtimes, and the detected operating system. It's very useful when you need to diagnose installation problems.
Choosing an editor or IDE
With the SDK installed you can already compile C# code, but writing it in a plain text editor would be quite uncomfortable: no autocomplete, no error detection as you type, no debugging support. That's why it's recommended to use a specialized editor or an IDE (Integrated Development Environment). Here are the three most common options:
| Tool | Type | Strengths | When to choose it |
|---|---|---|---|
| Visual Studio Code + C# Dev Kit | Lightweight editor + extension | Free, fast, cross-platform, highly extensible | Learning, small and medium projects, anyone already using VS Code |
| Visual Studio (Community/Professional) | Full IDE | Advanced visual tools (form designer, very powerful debugger) | Windows, desktop applications (WPF/Windows Forms), large projects |
| JetBrains Rider | Full IDE | Excellent refactoring, widely used by professional teams, cross-platform | Anyone already familiar with other JetBrains IDEs, professional projects |
There's no single "correct" option: all three let you write and run C# perfectly well. In this
course, the examples work the same regardless of your choice; we'll always use the dotnet CLI
to create and run projects, so the steps are identical no matter which editor you use.
Visual Studio Code with C# Dev Kit
Visual Studio Code (VS Code) is a lightweight, free code editor. On its own it doesn't understand C#; for that you install the official C# Dev Kit extension, which adds:
- Syntax highlighting and smart autocomplete.
- Error detection as you type (even before compiling).
- A built-in debugger to step through your code.
- Browsing of .NET projects and solutions right from the editor.
To install it: open VS Code, go to the extensions panel (the puzzle-piece icon in the sidebar), search for "C# Dev Kit", and install it with the corresponding button.
Visual Studio
Visual Studio is Microsoft's historic IDE for C# development, especially powerful on Windows. The Community edition is free for students, open-source projects, and small teams. When installing it, the installer lets you choose "workloads"; for this course, the ".NET desktop development" or ".NET cross-platform development" workload would be enough.
JetBrains Rider
Rider is a paid IDE (with a free trial period) developed by JetBrains, the same company behind IntelliJ IDEA. It's cross-platform (Windows, macOS, Linux) and highly regarded in professional environments for its refactoring and code analysis capabilities.
The structure of a console project created with dotnet new console
The dotnet CLI lets you create new projects from templates. The console template
generates a console application project, the simplest type of project and the one we'll work
with for a good part of this course. To create one:
The -o (for output) parameter specifies the name of the folder where the project will be
created. Running this command makes dotnet generate the following file structure:
Let's understand what each element is:
| Element | What it is |
|---|---|
MyProject.csproj |
The project file. An XML file describing how to build the project: which .NET version is used, project type, references to external packages, etc. |
Program.cs |
The main source code file. This is where we'll write our C# code. By default it already contains a sample "Hello World". |
obj/ |
A folder generated automatically with intermediate build files. It's not edited by hand; it can be safely deleted, since it regenerates itself. |
The first time you build the project, a bin/ folder will also appear, containing the already
compiled program, ready to run.
A quick look at the contents of the generated .csproj (no need to understand it all yet):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>OutputType>Exeindicates that the build output is an executable (a program that can be launched), rather than, say, a library.TargetFramework>net8.0indicates which version of .NET the project uses to build and run.ImplicitUsingsandNullableare modern settings that simplify the code; we'll come to understand them little by little throughout the course (implicit usings are covered in the basic syntax lesson, and nullability is introduced in the variables and data types lesson).
Basic dotnet CLI commands
Here are the dotnet commands you'll use constantly throughout the course:
| Command | What it does |
|---|---|
dotnet new console -o ProjectName |
Creates a new console project in the given folder |
dotnet restore |
Downloads and prepares the dependencies (packages) the project needs |
dotnet build |
Compiles the project (generates the executable) without running it |
dotnet run |
Compiles (if needed) and runs the project in a single step |
dotnet --version |
Shows the installed SDK version |
dotnet --info |
Shows detailed information about the installed .NET environment |
In day-to-day practice, the command you'll use the most is dotnet run, since it builds and
runs in a single step. The dotnet build and dotnet restore commands are useful when you want
to keep those steps separate, for example in an automated continuous integration pipeline.
Complete workflow example
This workflow creates the project, moves into its folder, and runs it directly. Since the project generated by the template already includes a sample "Hello World", you'll see something like:
In the next lesson we'll create exactly this project, name it BiblioTechConsole, and modify its contents to work with our own message.
Verifying that the environment works
Before continuing with the course, it's important to confirm everything is correctly installed. Follow this checklist:
- Run
dotnet --versionin a terminal and confirm that a version number appears (for example,8.0.100), with no errors. - Create a test project with
dotnet new console -o EnvironmentTest. - Go into the generated folder (
cd EnvironmentTest) and run it withdotnet run. - Confirm that the
Hello, World!message (or similar) appears in the terminal, with no build errors. - Open the project folder with your chosen editor (VS Code, Visual Studio, or Rider) and
confirm that the
Program.csfile opens with C# syntax highlighting and, if you've installed the corresponding extension or workload, with autocomplete. - Once you've confirmed everything works, you can delete the
EnvironmentTestfolder: it was just a test.
If all these steps work without errors, your environment is ready for the rest of the course.
Common Mistakes and Tips
- Forgetting to restart the terminal after installing the SDK: on many systems, the
terminal needs to be restarted (or the system itself, on Windows) to recognize the new
dotnetcommand. Ifdotnet --versiondoesn't work right after installing, try closing and reopening the terminal before digging any further. - Confusing
dotnet buildwithdotnet run:buildonly compiles (it generates the executable but doesn't launch it);runcompiles and also runs it. If you expect to see the program's output on screen, you needdotnet run. - Installing only the runtime instead of the SDK: there are separate downloads for "runtime" (only for running already-compiled programs) and "SDK" (for building and running). To develop, you need the SDK, not just the runtime.
- Mixing .NET versions unnecessarily: when starting out, there's no need to install several SDK versions at once. Install the latest LTS version and use it throughout the course, unless told otherwise.
- Tip: whichever editor you choose, spend a few minutes getting familiar with its file explorer and its integrated terminal; you'll use them constantly throughout the course.
Exercises
-
Install the .NET SDK (if you don't already have it) following the steps in this lesson, and run
dotnet --versionanddotnet --info. Note down what SDK version and what operating system the second command reports. -
Create a test console project named
EnvironmentTestwithdotnet new console. Without opening any editor yet, use your system's file explorer (or thels/dircommand) to examine what files and folders were generated, and match them against the table in this lesson. -
Run the
EnvironmentTestproject withdotnet run. Then open theProgram.csfile with the editor you chose and change the text"Hello, World!"to a different message, for example"BiblioTech environment ready!". Rundotnet runagain and confirm the new message appears on screen.
Solutions
-
The output will vary depending on your machine, but a typical example would be:
dotnet --version→8.0.100;dotnet --infoshowing the installed SDK, the operating system (for example,LinuxorWindows), and the architecture (x64,arm64, etc.). If the command fails, review the installation by following the steps in this lesson again. -
Creating the project generates, at minimum,
EnvironmentTest.csproj(the project file) andProgram.cs(source code), and after the first build anobj/folder will also appear (and, after running,bin/). This matches the structure described in the "Structure of a console project" section. -
After changing the line in
Program.cs(something likeConsole.WriteLine("BiblioTech environment ready!");) and runningdotnet runagain, the terminal should show:BiblioTech environment ready!. This confirms that the editor, the SDK, and thedotnetCLI are all working correctly together.
Conclusion
In this lesson you set up your complete development environment: the .NET SDK, an editor or
IDE of your choice, and the basic dotnet CLI commands (new, build, run, restore). You
also learned the minimal structure of a console project and confirmed, step by step, that
everything works correctly.
With the environment ready, in the next lesson, Hello World Program, we'll create the course's first real project — BiblioTechConsole — and analyze each part of the code line by line, including both the classic form and the modern (top-level statements) form of writing it.
C# Programming Course
Module 1: Introduction to C#
- Introduction to C#
- Setting Up the Development Environment
- Hello World Program
- Basic Syntax and Structure
- Variables and Data Types
- Arrays and Strings
Module 2: Control Structures
Module 3: Object-Oriented Programming
- Classes and Objects
- Methods
- Constructors and Destructors
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
- Structs and Records: Value Types and Reference Types
Module 4: Advanced C# Concepts
- Interfaces
- Delegates and Events
- Pattern Matching and Modern C# Features
- Generics
- Collections
- LINQ (Language Integrated Query)
- Asynchronous Programming
Module 5: Working with Data
- File I/O
- Serialization
- Database Connectivity
- Entity Framework
- Working with JSON and Consuming REST APIs
Module 6: Advanced Topics
- Reflection
- Attributes
- Dynamic Programming
- Memory Management and Garbage Collection
- Multithreading and Parallel Programming
Module 7: Building Applications
Module 8: Best Practices and Design Patterns
- Coding Standards and Best Practices
- Design Patterns
- Dependency Injection and Inversion of Control
- Unit Testing
- Code Review and Refactoring
