.NET Platform Fundamentals
Level: Beginner
- What is .NET and why it exists
- .NET Framework vs .NET Core vs .NET (modern)
- How .NET code compiles and runs
- CLR (Common Language Runtime) and MSIL
- NuGet packages and dependencies
- .NET project structure and csproj files
- Different .NET versions and when to use them
C# is a language. .NET is the platform that runs C# code. Understanding .NET means understanding how your code actually executes on computers, how packages work, and how to build production applications.
What is .NET?
.NET is a free, open-source platform for building applications.
Think of it this way:
- Language: C# (what you code in)
- Platform: .NET (what runs your code)
- Framework: ASP.NET Core (web application framework)
Example: You write School Management API in C#. .NET runtime executes it.
The Evolution: .NET Framework → .NET Core → .NET
This is confusing for beginners. Let me clarify:
.NET Framework (2002-2023) — Old
First version of .NET. Windows-only. Older companies still use it.
.NET Framework 4.8 (last version)
Problems:
- Only works on Windows
- Heavy, large installation
- Slow to update
- Not open-source
.NET Core (2016-2020) — Transition
Microsoft's response. Cross-platform. Open-source.
.NET Core 3.1 (last version)
Improvements:
- Works on Windows, Linux, Mac
- Lightweight
- Fast updates
- Open-source
.NET 5+ (2020-Now) — Modern
Renamed to just ".NET". Unified platform.
.NET 5, 6, 7, 8 (current), 9 (preview)
Current standard:
- Cross-platform
- Modern, fast, secure
- Regular updates (every year)
- Industry standard
For this course: Use .NET 8 (stable, production-ready)
How .NET Works — Compilation Process
When you write C# code and run it:
C# Code (.cs file)
↓ (C# Compiler)
MSIL Code (.dll/.exe)
↓ (JIT Compiler at runtime)
Native Machine Code (CPU-specific)
↓ (Execution)
Running Application
Step 1: Compilation (C# Compiler)
Your C# code compiles to MSIL (Microsoft Intermediate Language).
MSIL is not native machine code. It's intermediate code that any CPU can understand (after one more step).
// C# Code
int total = 5 + 3;
Becomes MSIL:
ldc.i4.5 ; load 5
ldc.i4.3 ; load 3
add ; add them
stloc.0 ; store result
Step 2: Runtime Execution (JIT Compiler)
When your program runs, .NET's CLR (Common Language Runtime) takes MSIL and compiles it to native machine code.
This happens just-in-time (JIT) — right when you need it.
Advantages:
- MSIL works on any OS (.NET installed there)
- JIT optimizes for the specific CPU
- Single codebase, multiple platforms
Example: School Management API
Developer writes: new SchoolRepository()
↓ (C# Compiler)
MSIL: newobj SchoolRepository
↓ (JIT at runtime)
Native: Create object at memory address 0x7FFF1234
↓ (Execution)
SchoolRepository instance runs
The CLR — Common Language Runtime
The CLR is like the engine that runs your code.
What CLR does:
- Loads MSIL code
- Compiles to native code (JIT)
- Manages memory (garbage collection)
- Handles exceptions
- Enforces security
Why "Common"? Many languages compile to MSIL: C#, VB.NET, F#. All run on same CLR.
NuGet — Package Manager
NuGet is like App Store for code libraries.
What it solves: You need Entity Framework Core for your School Management API. You can:
Bad way (old): Download DLL from website, copy to project
Good way (NuGet): dotnet add package Microsoft.EntityFrameworkCore
NuGet automatically downloads and installs the package and its dependencies.
Using NuGet
In Visual Studio:
Tools → NuGet Package Manager → Package Manager Console
Install-Package Microsoft.EntityFrameworkCore
Via CLI:
dotnet add package Microsoft.EntityFrameworkCore
NuGet stores packages in .csproj file (project file).
Project Structure
When you create a .NET project, you get this structure:
SchoolAPI/
├── bin/ → Compiled output (.dll files)
├── obj/ → Temporary build files
├── Properties/ → Version, settings
├── SchoolAPI.csproj → Project file (NuGet packages, configuration)
├── Program.cs → Entry point (Main method)
├── Controllers/ → API endpoints (ASP.NET Core)
├── Models/ → Data classes (Student, Teacher, etc.)
├── Data/ → Database access
└── appsettings.json → Configuration (database connection, etc.)
.csproj File (Project File)
This file defines your project:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
</ItemGroup>
</Project>
What it says:
- Target framework: .NET 8.0
- Uses Web SDK (ASP.NET Core)
- Needs Entity Framework Core package version 8.0.0
.NET Versions — Which One to Use?
| Version | Released | Status | Use Case |
|---|---|---|---|
| .NET Framework 4.8 | 2019 | Legacy | Old enterprise apps |
| .NET 5 | Nov 2020 | End of Life | Don't use |
| .NET 6 | Nov 2021 | LTS | Long-term support |
| .NET 7 | Nov 2022 | End of Life | Don't use |
| .NET 8 | Nov 2023 | LTS (Current) | Use this |
| .NET 9 | Nov 2024 | Latest | Bleeding edge |
LTS = Long Term Support (3 years)
For learning: Use .NET 8
- Stable, production-ready
- Long support period
- Industry standard
- All features you need
How Code Executes — Simple Example
You write:
class Program
{
static void Main()
{
int result = Add(5, 3);
Console.WriteLine(result);
}
static int Add(int a, int b)
{
return a + b;
}
}
What happens:
- C# Compiler reads code → MSIL
- You run:
dotnet runordotnet .\SchoolAPI.dll - .NET Runtime (CLR) starts
- CLR loads MSIL
- CLR JIT-compiles Main() to native code
- CPU executes native code
- Main() calls Add() → JIT-compiles Add() → executes
- Result: 8 printed, program exits
Memory management:
- CLR allocates memory for
resultvariable - After Main() finishes, CLR garbage collection frees memory
- Developer doesn't manually manage memory (unlike C/C++)
Managed vs Unmanaged Code
Managed Code (C#, VB.NET)
- Runs inside CLR
- Automatic memory management
- Type-safe
- Security checks
Unmanaged Code (C, C++)
- Runs directly on OS
- Manual memory management
- Faster but dangerous
- Programmer responsible for cleanup
.NET is managed code platform. CLR takes care of memory.
.NET Compilation Modes
Debug Mode
dotnet build
Creates MSIL with debugging information. Slower, easier to debug.
Release Mode
dotnet build -c Release
Creates optimized MSIL. Faster, smaller, harder to debug.
Use Release for production deployment.
.NET Tools You Need
| Tool | Purpose |
|---|---|
| .NET SDK | Contains compiler, runtime, tools |
| Visual Studio | IDE (development environment) |
| NuGet | Package manager |
| dotnet CLI | Command-line tool |
| Git | Version control |
Supported Languages on .NET
.NET supports languages that compile to MSIL:
- C# — Primary language (what you'll use)
- VB.NET — Visual Basic version of .NET
- F# — Functional programming language
- PowerShell — Scripting language
All run on same CLR, can call each other.
Why .NET for School Management System?
School API requirements:
- REST API (ASP.NET Core) ✓
- Database (Entity Framework Core + SQL Server) ✓
- Authentication (built-in) ✓
- Performance (optimized CLR) ✓
- Cross-platform (Windows, Linux, Docker) ✓
- Job market demand (India tech jobs) ✓
Common Misconceptions
Myth 1: ".NET only works on Windows"
- Reality: .NET 5+ works on Windows, Linux, Mac
Myth 2: "C# and .NET are the same"
- Reality: C# is language, .NET is platform
Myth 3: ".NET is slow"
- Reality: JIT compilation makes .NET very fast
Myth 4: ".NET requires Visual Studio"
- Reality: Works fine with VS Code + dotnet CLI
Myth 5: ".NET is only for web"
- Reality: Desktop apps, mobile (MAUI), games (Unity), console apps
Quick Recap
| Concept | What It Is |
|---|---|
| .NET | Platform for running applications |
| C# | Programming language |
| CLR | Runtime engine that executes code |
| MSIL | Intermediate code before execution |
| JIT | Compiler that converts MSIL to native code |
| NuGet | Package manager for libraries |
| .NET 8 | Current stable version |
| csproj | Project configuration file |
Q: How does .NET code compile and execute? Explain the role of CLR and MSIL.
Good Answer: "When I write C# code, the C# compiler first compiles it to MSIL (Microsoft Intermediate Language), which is platform-independent bytecode stored in DLL or EXE files. When the program runs, the .NET Runtime (CLR - Common Language Runtime) takes this MSIL code and uses a JIT (Just-In-Time) compiler to convert it to native machine code specific to the CPU at runtime. The CLR also handles memory management through garbage collection, so I don't have to manually free memory like in C++. This design allows the same MSIL code to run on Windows, Linux, or Mac without recompilation."
Use ChatGPT, Claude, or Copilot to go deeper on .NET platform fundamentals. Try these prompts:
"Explain the difference between .NET Framework, .NET Core, and .NET 5+""What is MSIL and how is it different from native machine code?""What does the CLR do and why is it important?""How do I use NuGet to add packages to my .NET project?"
💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.