C# · Basics

Installing the .NET SDK

Before you write C#, you need the .NET SDK — one free download that gives you the compiler, the runtime and the dotnet command-line tool.

Beginner 5 min Lesson 2 of 26Examples target C# 13 on .NET 9 unless stated otherwise.
Before you start:Introduction to C#
0/26 in C#
On this page · 5 min · Beginner

In simple words#

Installing the .NET SDK is like buying a full toolbox before starting carpentry. Without it you can read plans (code) but you cannot build anything.

SDK
Software Development Kit — compiler + tools to build apps.
Runtime
Only what is needed to run apps, not build them.
dotnet CLI
The command-line tool: dotnet new, dotnet run, dotnet build.

Learning objectives#

  • Install the .NET SDK and check the version
  • Create a console project with dotnet new
  • Build and run with dotnet run
  • Understand the files in a new project

Explanation#

Download the .NET SDK from dot.net (choose the latest LTS version if unsure). The SDK includes the runtime, so you do not need both.

After installing, open a new terminal and run dotnet --version. If you see a version number, everything works.

dotnet new console -n HelloApp creates a folder HelloApp with two important files: Program.cs (your code) and HelloApp.csproj (the project file that says which .NET version to target).

dotnet run builds and runs the project in one step. dotnet build only compiles; the output goes into the bin folder.

For an editor, use Visual Studio (Windows, full IDE), VS Code with the C# Dev Kit extension (any OS, lightweight) or JetBrains Rider.

Syntax#

Shell Illustrative
dotnet --version              # check the SDK is installed
dotnet new console -n MyApp   # create a project
dotnet run                    # build + run (inside the project folder)

Code example: From nothing to a running app#

ShellFrom nothing to a running app Illustrative
dotnet --version
# 9.0.100


dotnet new console -n HelloApp
cd HelloApp
dotnet run
# Hello, World!


dotnet new list               # see all project templates (webapi, mvc, blazor...)
Expected output
dotnet --version prints the installed SDK version. dotnet new creates HelloApp/Program.cs and HelloApp/HelloApp.csproj. dotnet run compiles the project and prints “Hello, World!”.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. dotnet --version confirms the SDK is on your PATH.
  2. dotnet new console uses the console-app template; -n sets the project and folder name.
  3. cd HelloApp moves into the project folder, where the .csproj file lives.
  4. dotnet run restores packages, compiles and runs Program.cs.
  5. dotnet new list shows the other templates you will use later: webapi, mvc, blazor, xunit.

Real-world use case#

Every .NET project — a console tool, an ASP.NET Core API or a Blazor site — is created, built, tested and published with the same dotnet CLI. CI pipelines in GitHub Actions and Azure DevOps run exactly these commands.

Common mistakes#

“dotnet is not recognized”

The terminal was opened before installing. Close and reopen it (or restart VS Code) so it picks up the new PATH.

Running dotnet run in the wrong folder

“Couldn’t find a project to run” means there is no .csproj in the current folder. cd into the project folder first.

Installing only the runtime

The runtime can run apps but cannot build them. Developers need the SDK.

Best practices#

  • Install the SDK, not just the runtime
  • Keep one project per folder
  • Use dotnet watch run while learning — it reruns on every save
  • Commit the .csproj but ignore bin/ and obj/ in git

Remember this#

SDK = tools to build. Runtime = only to run.

new → run → build: dotnet new, dotnet run, dotnet build.

.csproj is the project file; Program.cs is where code starts.

Practice exercise#

Your task: Create a console app called Greeter, change Program.cs so it prints "Setup complete!", and run it.

Need a hint?
dotnet new console -n Greeter, then edit the Console.WriteLine line.
Show solution
Shell Illustrative
dotnet new console -n Greeter
cd Greeter
# edit Program.cs: Console.WriteLine("Setup complete!");
dotnet run
# Setup complete!

Mini quiz#

Installing the .NET SDK quizMultiple choice Question 1 of 3

Which command creates a new console project?

Score so far: 0/0

Want more? Practise all C# MCQs · C# interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.