Running a .NET Project

C# From Scratch Part 2.2

Ken Bourke
Dec 14, 2020 · 4 min read
Output of dotnet run

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 how to create a new .NET project using the .NET CLI and the dotnet new command. We used this command to create a .NET Console Application. If you missed it, that part of the series is available here.

In this part of the series, we’ll explore the structure of the .NET project that we have just created and learn how to run the project in a Command Prompt window.

Exploring the Project

You can see that the directory now contains two files — Program.cs and src.csproj

Contents of the src directory

The .csproj extension indicates that this is a C# Project file. It contains information about the project.

The .cs extension indicates that this is a C# source code file. This file contains all of the source code for our application.

Running the Application

When you use this command, the application runs and the output ‘Hello World!’ is printed to the Command Prompt window.

Output of dotnet run

We know that the application is working since it produces the default output, but what exactly is happening when we use the dotnet run command?

Behind the Scenes

Restore

Packages are pieces of codes that other developers have written and you can use in your application. In the world of .NET, the package system is called NUGET.

All of the packages being used by your application are recorded in the .csproj file, along with the version of the package being used. When the dotnet restore command is executed, .NET goes out and gets each package listed in your .csproj file from the internet.

The packages that are used in your application are called external dependencies.

In our basic project, we don’t have any external dependencies so nothing happens when .NET runs this command.

Build

This command tells .NET to compile your source code files into a binary file that can execute on your machine.

The tool that does this is the C# compiler. The C# compiler takes all of the source code files in your project as an input and outputs a single binary representation of your source code. This binary format is faster to execute on your machine.

The output file is a dll file.

Dll stands for Dynamic Linked Library. In .NET, this is referred to as an assembly.

Run

This command tells .NET to bring the application to life using the .NET Core Runtime and to execute the instructions in the dll file.

It’s important to note that if you want to run your application, you need to use the .NET Core Runtime. It’s not possible to run the application via the dll file directly.

This is because it’s the .NET Core Runtime that knows how to launch your application, manage memory, convert the instructions in the dll file into instructions that your processor understands and tear down the application when it’s finished running.

What’s Next?

In the next part of the series, we’ll learn how to open the project in Visual Studio Code and look at the most important parts of our code editor. You can find that part of the series here.

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

The Startup

Get smarter at building your thing. Join The Startup’s +724K followers.

Ken Bourke

Written by

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

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +724K followers.

Ken Bourke

Written by

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

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +724K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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