How to create and run C# project

This post is just a reminder for me. So in order to find more details about dotnet CLI, follow the below link

Creating a C# Project

Creating a Console Project

dotnet new console -o console-demo1

Creating a WebApi Project

dotnet new webapi -o webapi-todo-demo1

1. Creating a C# Console Project

-o or –output is location to place for new generated project.

dotnet new console -o enum_demo4
Folder Structure
Generated Project

2. Building – Compiling Project

Build the project in the current directory. It build project and its dependencies.

dotnet build

Build the specified project

dotnet build ./demo_app1

Build project and its dependencies using Release configuration

dotnet build --configuration Release

3. Running

Run the project in the current directory:

dotnet run

Run the specified project

dotnet run --project ./demo_app1/demo_app1.csproj


dotnet run -p./demo_app1/demo_app1.csproj

4. Cleaning

Clean the project in the current directory:

dotnet clean

Clean specified project:

dotnet clean ./demo_app1

Leave a Reply