Working with the .NET CLI

C# From Scratch Part 2.0

Welcome to another part of the series C# From Scratch, a course dedicated to teaching you everything you need to know to be productive with the C# programming language.

In the previous part of the series, we learned what .NET does for our applications and why we need it to run applications we write in C#. That part of the series is available here.

In this part of the series, we’ll get hands on with the .NET Command Line Interface, a tool that is installed as part of the .NET SDK to make developing .NET applications easier.

Accessing the .NET CLI

The .NET Command Line Interface is installed on your machine as part of the .NET SDK installation.

Once the .NET CLI is installed on your machine, you can access it through a Command Prompt window (also known as a terminal or shell depending on your operating system).

On a Windows machine, you can launch the command prompt by going to the Start menu and typing ‘cmd’. Press enter to launch the Command Prompt app.

Access the Command Prompt app through the Start menu

Using the Command Prompt, you can run the .NET CLI by typing the command ‘dotnet’ and pressing enter.

Access the .NET CLI using the command ‘dotnet’

The .NET CLI provides some output to the Command Prompt window. This output shows us that the CLI is correctly installed and that to use the CLI, we need to provide some options along with the dotnet command.

Working the .NET CLI Options

The output from the dotnet command provides us with a list of options that we can use with the command.

Let’s start by using the ‘-info’ option. Running the dotnet command with the info option provides us with information about the versions of .NET that we are using. This can be very useful if you are trying to troubleshoot an application or your environment.

Run the dotnet command again with the info option.

.NET info option

There is also a help option available. This option displays a list of all the possible commands that are available as part of the .NET SDK.

Run the dotnet command again with the help option.

.NET help option

From the output, we can see that if we wanted to build a .NET project, we could use the ‘build’ command. Building is the process of converting source code into an executable that can be run by your machine.

There is also a ‘test’ command which we could use to run unit tests on our application. Tests are an invaluable resource for developers because they help to ensure that your program is working correctly.

Finally, there is a ‘new’ command. This command is used to create a new .NET project.

A project is a collection of source code files that will be compiled into a single application. Before you create an application, you have to create a project with source code and build the project into an application.

What’s Next?

In this part of the series, we learned how to launch the .NET CLI and use options to get information about the SDK and the commands that are available to use.

In the next part of the series, we’ll use the ‘new’ command to create our first C# application.

Missed a part of the series? You can find an overview of the series and links to all previous parts on the index page.

Automation Engineer, Technology Enthusiast, Freelance/Consulting. Official website: https://www.kb-controls.io/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store