Lesson 2 / 26
Your First App with the CLI
Create, run and publish a console app using only the dotnet command line.
The dotnet CLI
Every task has a verb: dotnet new creates a project, dotnet run builds and runs it, dotnet build only compiles, and dotnet publish prepares it for deployment.
Create and run
These three commands scaffold a console project, move into it and run it. dotnet new console creates a .csproj and a Program.cs.
dotnet new console -o HelloApp
cd HelloApp
dotnet run
Output:
Hello, World!
Check your version
Run dotnet --info when something behaves oddly. It shows which SDK you are using; a global.json file in a parent folder can pin a different one than you expect.
Quick check: Which command builds the project and then starts it?
- dotnet new
- dotnet run
- dotnet add
- dotnet restore
Answer
dotnet run — `dotnet run` restores, builds and launches the app in one step.