Beginner · Getting started with C# and .NET · topic 2 of 43 · 25 min
Installing .NET and using the dotnet CLI
Explanation
Why a command line?
A CLI (Command-Line Interface) is a program you control by typing commands in a terminal instead of clicking buttons. The .NET CLI is one program named dotnet. It creates projects, builds them, runs them, runs tests and installs packages. Big editors like Visual Studio call the same dotnet tool behind the scenes, so learning it helps you everywhere: on your laptop, on a Linux server and in automated build pipelines.
Step 1: install the SDK
- Go to dotnet.microsoft.com and open the Download page.
- Download the SDK (not only the runtime) for the latest LTS version, for your operating system.
- Run the installer. On Linux you can also use your package manager; the download page shows the commands.
- Close and reopen your terminal so it finds the new dotnet command.
dotnet --version
dotnet --list-sdksStep 2: pick an editor
- Visual Studio Code with the C# Dev Kit extension: free, works on all systems, light on old laptops.
- Visual Studio Community: a full IDE (Integrated Development Environment) for Windows, free for students and individuals.
- JetBrains Rider: a full IDE for all systems, free for non-commercial use.
Step 3: create and run a project
dotnet new console -o Hello
cd Hello
dotnet runHello, World!A template is a ready-made starting project. dotnet new list shows all installed templates: console, classlib (a library), webapi, xunit (tests) and more.
What is inside the folder?
| File or folder | What it is |
|---|---|
| Program.cs | Your C# code. |
| Hello.csproj | The project file: settings in XML. |
| obj/ | Temporary files the build uses. Created automatically. |
| bin/ | The build output: Hello.dll and friends, inside bin/Debug/net10.0/ (the last part matches your version). |
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>The everyday commands
| Command | What it does |
|---|---|
| dotnet new console -o Name | Create a new console project in a folder |
| dotnet build | Compile only; shows errors and warnings |
| dotnet run | Build if needed, then run |
| dotnet watch | Run, and rebuild automatically when you save a file |
| dotnet clean | Delete the build output |
| dotnet add package Name | Add a NuGet package (module 9) |
| dotnet publish -c Release | Make a release build ready to copy to a server |
Common mistakes and fixes
- "dotnet is not recognized as a command": the terminal was open before the install. Close it and open a new one. If it still fails, restart the computer.
- "Couldn't find a project to run": you are in the wrong folder. Use cd to go into the folder that has the .csproj file.
- Committing bin/ and obj/ to Git: they are rebuilt every time and are large. Run dotnet new gitignore once in your project to create a .gitignore that skips them.
- Installing only the runtime: you can run apps but not build them. Install the SDK.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Installing .NET and using the dotnet CLI · 1/7
In this lesson you will install the .NET SDK and use the dotnet command to create and run your first project.
Prefer a video by a teacher? Find free videos on “install .NET SDK dotnet new console dotnet run tutorial” on YouTube ↗
In real life: Setting up a college lab in one hour
A lab assistant at an engineering college in Nagpur sets up 40 computers for a C# class. She installs the .NET SDK and VS Code on each one, then checks every machine with dotnet --version. Students create their first app with dotnet new console, so nobody needs a paid licence.
dotnet --version
dotnet new console -o MarksApp
cd MarksApp
dotnet runPractice (0/3 done)
Which command creates a new console project in a folder named Shop?
You type dotnet run and see "Couldn't find a project to run". What is the most likely cause?
On your own computer: install the .NET SDK, create a console app named Hello, run it, then change the message to print your name and run it again.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Your first program: output, input and the Main methodGetting started with C# and .NET · same module
- Types and variablesGetting started with C# and .NET · same module
- NuGet packages, solutions and project structureTesting, tooling and Unity
- ASP.NET Core: your first Web APIWeb APIs with ASP.NET Core and EF Core
- Unit testing with xUnitTesting, tooling and Unity
- Installing the JDK and your first programJava Programming (Core to Spring Boot) · Getting started with Java
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is the difference between dotnet build and dotnet run?
Answer: build only compiles; run compiles if needed and then runs
dotnet build checks and compiles. dotnet run also starts the program.
Which file tells .NET the project's target version?
Answer: The .csproj file
The <TargetFramework> element in the .csproj, for example net10.0.
Should you commit the bin and obj folders to Git?
Answer: No, they are build output and are recreated by every build
They are generated files. Add them to .gitignore (dotnet new gitignore does it).
What do you need to install to BUILD C# programs?
Answer: The .NET SDK
The SDK has the compiler and the dotnet tools. The runtime alone can only run built apps.
Which command reruns your app automatically when you save a file?
Answer: dotnet watch
dotnet watch rebuilds and restarts when files change.
Where is a package dependency recorded?Related
Answer: As a PackageReference in the .csproj
The .csproj lists PackageReference items.
Which .NET versions are Long Term Support (LTS)?Related
Answer: Even-numbered ones like 8 and 10
Even-numbered releases are LTS with three years of support.
From What C# and .NET are
Since which version does a new ASP.NET Core app start from Program.cs without Startup.cs?Related
What does dotnet test do?Related
Answer: Builds the projects and runs all the tests
It builds and runs tests, reporting passes and failures.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Getting started with C# and .NET” before its exam: Your first program: output, input and the Main method, Types and variables, Operators, conversions and parsing input.
- Module 1 exam: Getting started with C# and .NET · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Decisions, loops and methods. 43 topics left in the course before the final exam.