C# Q & A


How to use the .NET Core CLI to build and run applications?

Using the .NET Core CLI (Command-Line Interface) to build and run C# applications is a straightforward and efficient process. Here’s a step-by-step guide on how to do it:


  1. Installation: First, ensure that you have the .NET Core SDK installed on your machine. You can download it from the official .NET website (https://dotnet.microsoft.com/download/dotnet-core). Once installed, open your command prompt or terminal.


  1. Creating a New Project: To create a new C# project, navigate to the directory where you want to create the project and run the following command, replacing “MyApp” with your preferred project name:
dotnet new console -n MyApp

This command creates a new console application project named “MyApp.”


  1. Building the Project: After creating the project, navigate to its directory using the `cd` command:
cd MyApp

To build the project, use the `dotnet build` command:

  dotnet build

  This command compiles your C# code and generates the necessary executable files.


  1. Running the Application: To execute your C# application, use the `dotnet run` command:
 dotnet run


   This command runs your application, and you should see the output in the terminal.


  1. Testing: If your project includes unit tests, you can run them with the `dotnet test` command:
dotnet test

   This command executes all the tests in your project and provides test result summaries.


  1. Publishing: When you’re ready to publish your application for distribution or deployment, you can use the `dotnet publish` command. This command packages your application and its dependencies for the target platform.


  1. Cleaning: To clean your project and remove build artifacts, use the `dotnet clean` command:
dotnet clean

  This helps keep your project directory tidy.


By following these steps, you can efficiently build, run, test, and publish C# applications using the .NET Core CLI. It’s a versatile tool that simplifies development tasks and provides cross-platform support, making it an excellent choice for C# developers working on a wide range of projects.


Previously at
Flag Argentina
time icon
Experienced Backend Developer with 6 years of experience in C#. Proficient in C#, .NET, and Java.Proficient in REST web services and web app development.