Introduction
Microsoft has just released .NET 7 on 14th November 2022. In the previous articles, we looked at some of the new features.
- Using Struct Default Values In .NET 7
- Using Multi-Line String Literals In .NET 7
- Using The New Required Keyword In .NET 7
- Using The New Generics Pattern Matching Feature In .NET 7
- Using The New Generic Number Interface In .NET 7
- New File Scope Feature In .NET 7
- New Features In .NET 7
Today, we will look at another feature introduced with .NET 7 and that is the Ahead of Time (AOT) compilation to native code.
AOT compilation to native code
In standard .NET development, we compile and build our code to Intermediate Language (IL). Then, when we run the application, the JIT (Just-In-Time) compiler, compiles it to native code and runs it. This is the reason for the slight delay we see when we first run an application. With the new feature in .NET 7, we can compile our code directly to the native version and hence the first run is also very fast. The process to do this is quite simple and we will look at it below. Let us create a console application using Visual Studio 2022 Community edition.



Now, add the below code to the “Program.cs” file.








Join the conversation! Your thoughts help the community grow.