In the last lesson, we built and ran our first project. Let's take a closer look at the process of compiling and running code in C#.
Compilation is the process of assembling information from various sources into one location. In software development, this means transforming the code a developer writes into machine readable code which can be executed by a micro-processor.
All code is compiled. But this can happen in more than one way.
With C#, our computers do not interpret the code we write. Instead, our code is a set of instructions to build a program.
With this type of compilation, our code must be compiled into a different format that is optimized for our machines. The code is often compiled to binary files and is saved to disc separate from the code we write. It would be very challenging for humans to read this code.
This compilation happens long before a user ever encounters our program and is called Ahead Of Time compiling or AOT for short.
Several steps occur when we run the command
First, the runtime, or environment that processes the code, is invoked. In the case of .NET 5, this is a process called MSBuild. The MSBuild process looks through our project file and decides what resources it will need to build our program (just as a cook might decide which ingredients are needed for a recipe).
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net5.0</TargetFramework> </PropertyGroup> </Project>
In the big picture, here is what happens in this code:
"Microsoft.NET.Sdk", a software development kit which contains the C# language and many libraries of information.
Exeoutput, meaning a program that can be run.
net5.0framework, which contains a lot of our code libraries. We'll learn more about those later.
Compiling: Translating one type of code into another type. Generally this refers to translating a more human-readable type of code into a more complex type of code meant only for computers.
Ahead of Time: When code is compiled ahead of time, as is the case with C#.
Lesson 2 of 5
Last updated more than 3 months ago.