Compilation Process in .NET
In .NET, your code doesn’t run directly — it goes through a smart compilation process. Let’s understand how C# code is turned into machine-executable instructions via Intermediate Language (IL), Just-In-Time (JIT) compilation, and the CLR.
How .NET Compiles Code
The .NET compilation process involves multiple stages:
- Source Code – You write code in C# (or another .NET language)
- C# Compiler (csc.exe) – Compiles code into IL (Intermediate Language)
- Metadata + IL – Stored in an assembly (.dll or .exe)
- CLR + JIT – Converts IL to native machine code at runtime
What is Intermediate Language (IL)?
IL is a CPU-independent set of instructions generated by the C# compiler. It’s stored in your .NET assemblies and understood by the CLR.
You can view IL using a tool like ILDasm or dotnet IL disassembler.
// C# Code
Console.WriteLine("Hello");
// IL equivalent (simplified)
IL_0001: ldstr "Hello"
IL_0006: call void [System.Console]WriteLine(string)
JIT – Just-In-Time Compilation
When your app runs, the CLR uses a JIT compiler to convert IL into native machine code, just before it’s executed. This process is optimized and cached.
Benefits of JIT:
- Allows runtime optimization for specific CPU architectures
- Converts only the code that’s actually used
- Supports diagnostics and debugging at runtime
Note: JIT runs once per method per process unless it's recompiled.
Ready-to-Run (R2R) and AOT Compilation
With .NET Core and .NET 5+, Microsoft introduced Ready-to-Run (R2R) images and Ahead-of-Time (AOT) compilation for faster startup.
- R2R: Precompiles IL to native code during publish
- AOT: Converts entire app to native code at build time (used in .NET Native & MAUI)
// Publish with Ready-to-Run
dotnet publish -c Release -r win-x64 --self-contained true /p:PublishReadyToRun=true
Diagram: Compilation Flow
Source Code (.cs) → IL (.dll/.exe) → Native Code (JIT or AOT) → Executed by CPU
The .NET compilation process is designed for flexibility, performance, and cross-platform support. From writing code to executing machine instructions, .NET handles it all through IL, JIT, and the CLR. Now that you understand how code runs, let’s explore how Visual Studio helps you build and debug applications efficiently.