What are the key differences between .NET Framework, .NET Core, and .NET 5+?
10 minintermediate.NETframeworkcoreplatform
Quick Answer
.NET Framework is Windows-only, closed-source, and requires framework installation. .NET Core is cross-platform, open-source, supports side-by-side deployment, and has better performance. .NET 5+ is the unified platform combining Framework and Core benefits with improved performance, modern features, and long-term support. Use .NET 5+ for new development.
Detailed Answer
The .NET ecosystem has evolved significantly, with different versions serving different purposes and platforms.
Historical Timeline:
- .NET Framework (2002): Original .NET platform for Windows
- .NET Core (2016): Cross-platform, open-source rewrite
- .NET 5+ (2020): Unified platform combining Framework and Core
Key Differences:
| Feature | .NET Framework | .NET Core | .NET 5+ |
|---|---|---|---|
| Platform Support | Windows only | Cross-platform | Cross-platform |
| Open Source | No | Yes | Yes |
| Side-by-side | No | Yes | Yes |
| Performance | Good | Better | Best |
| Deployment | Framework-dependent | Self-contained | Self-contained |
| Package Size | Large | Smaller | Smallest |
| Docker Support | Limited | Excellent | Excellent |
.NET Framework:
// .NET Framework - Windows only
// Uses System.Web for web applications
// Requires .NET Framework runtime installed
// Larger package size
// Limited cross-platform support
// Example: ASP.NET Web Forms (Framework only)
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Framework-specific code
}
}
.NET Core:
// .NET Core - Cross-platform
// Modern, lightweight, fast
// Self-contained deployments
// Better performance
// Docker-friendly
// Example: ASP.NET Core Web API
[ApiController]
[Route("api/[controller]")]
public class WeatherController : ControllerBase
{
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
// Core-specific code
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55)
});
}
}
.NET 5+ (Unified):
// .NET 5+ - Best of both worlds
// Single platform for all scenarios
// Improved performance
// Modern language features
// Long-term support versions
// Example: Modern .NET 6+ Web API
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
Migration Path:
// .NET Framework → .NET Core → .NET 5+
// 1. Update project file format
// 2. Replace Framework-specific APIs
// 3. Update dependencies
// 4. Test cross-platform compatibility
// Old .NET Framework project file
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
</PropertyGroup>
</Project>
// New .NET 5+ project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
When to Use Each:
.NET Framework:
- Legacy Windows applications
- When you need Windows-specific features
- Existing applications that are difficult to migrate
- When you need specific Framework-only libraries
.NET Core:
- New cross-platform applications
- Microservices and containers
- High-performance scenarios
- Cloud-native applications
.NET 5+:
- All new development (recommended)
- Modern applications
- When you want the latest features
- Long-term support and updates
Performance Comparison:
// Benchmark results (approximate)
// .NET Framework: Baseline
// .NET Core: 2-3x faster
// .NET 5+: 3-4x faster
// .NET 6+: 4-5x faster
// Example: JSON serialization performance
var data = new { Name = "John", Age = 30 };
var json = JsonSerializer.Serialize(data); // Much faster in .NET 5+
Package Size Comparison:
.NET Framework: ~50MB (runtime)
.NET Core: ~30MB (runtime)
.NET 5+: ~25MB (runtime)
Self-contained: ~100MB+ (includes runtime)
API Differences:
// .NET Framework
using System.Web;
using System.Web.Mvc;
// .NET Core/5+
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
// Configuration differences
// Framework: web.config, app.config
// Core/5+: appsettings.json, environment variables
Best Practices:
- Use .NET 5+ for all new development
- Migrate gradually from Framework to .NET 5+
- Test thoroughly when migrating
- Use self-contained deployments for containers
- Leverage cross-platform benefits when possible
- Keep dependencies updated for security and performance