Working with the .NET CLI

C# From Scratch Part 1.2. In this part of the series, we learn how to interact with .NET using the .NET Command Line Interface, or .NET CLI.

Welcome to another edition of C# From Scratch, a course dedicated to teaching you everything you need to know to be productive with C#. If you’re new here, head over to the index to see all parts of the series.

In the last part of the series, we installed the .NET SDK on our machine. This SDK includes the .NET Runtime and some tools that help us to interact with .NET on our machines.

In this part of the series, we’ll learn how to interact with .NET using the .NET Command Line Interface, or .NET CLI. We will use the .NET CLI to create and run our first C# .NET application.

The .NET CLI

We use the .NET CLI in a Command Prompt window.

To open a Command Prompt window, open your Start menu and type cmd. One of the apps listed there will be the Command Prompt app.

Command Prompt App

Launch the Command Prompt app.

In the Command Prompt, launch the .NET CLI with the command dotnet. When you run this command, you get some feedback saying that the command expects some options or a path to an application.

Run the dotnet command

A very useful option is the -h option which displays the help information for the .NET CLI.

Run the dotnet command again with the -h option.

.NET help

The output from this option displays a list of SDK commands that can be used to get the .NET CLI to perform different tasks.

Let’s look at some of the most important commands available.

dotnet new

The dotnet new command is used to create a new .NET project.

A project is a collection of source code files that will be put together to create a single application. Before we can create an application that runs on our machine, we must create a project which contains the source code for the application.

dotnet build

Building is the process of converting C# source code into an executable file that can run on our machine. The dotnet build command tells .NET to convert your project into an executable file that .NET can load and execute on your machine.

dotnet test

The dotnet test command tells .NET to execute a unit test project for your application. These unit tests are used to verify that your code is working correctly in an automated way.

Conclusion

In this part of the series, we learned how to interact with .NET using the .NET CLI in a Command Prompt window.

In the next part of the series, we will learn how to use the .NET CLI to create a new C# .NET application.

Learn Something New Every Week

Sign up to the mailing list to get a new post about industrial automation and controls engineering delivered to your inbox every week.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

PLC Bootcamp

Learn the skills you need to start your journey as a PLC programmer. Enroll in PLC Bootcamp to learn how to write and test your first PLC program for free.