.NET Framework to .NET 8+ modernization patterns. **Use when:** User has a .NET Framework 4.x application and needs to upgrade to .NET 8 LTS. **Triggers on:** .csproj files with TargetFrameworkVersion, web.config files, System.Web references, Entity Framework 6. **Covers:** Project file transformation, web.config to appsettings.json, EF6 to EF Core, Windows/Forms auth to Entra ID.
Use this skill when modernizing .NET Framework applications to .NET 8+ for Azure compatibility.
| Legacy Version | Target Version | Notes |
|---|---|---|
| .NET Framework 4.5-4.8 | .NET 8 LTS | Recommended for production |
| .NET Core 2.1/3.1 | .NET 8 LTS | Straightforward upgrade |
| .NET 5/6/7 | .NET 8 LTS | Minor breaking changes |
<!-- Legacy format -->
<Project ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Web" />
</ItemGroup>
</Project>
<!-- Modern SDK-style -->
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
| web.config Element | appsettings.json Equivalent |
|---|---|
<connectionStrings> | "ConnectionStrings": { } |
<appSettings> | "AppSettings": { } or custom section |
<system.web> | Middleware configuration in Program.cs |
<system.webServer> | Kestrel/IIS configuration |
<customErrors> | Exception handling middleware |
See appsettings.json template for a complete example.
// Legacy Windows Auth
[Authorize]
public class SecureController : Controller
{
var user = User.Identity.Name; // DOMAIN\username
}
// Modern Entra ID
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"));
[Authorize]
public class SecureController : ControllerBase
{
var user = User.FindFirst(ClaimTypes.Name)?.Value;
}
// Legacy Forms Auth in web.config
// <authentication mode="Forms">
// <forms loginUrl="~/Account/Login" />
// </authentication>
// Modern ASP.NET Core Identity
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Account/Login";
});
| EF6 Pattern | EF Core Equivalent |
|---|---|
DbContext with DbSet<T> | Same pattern, different namespace |
Database.SetInitializer | DbContext.Database.EnsureCreated() or migrations |
DbConfiguration | OnConfiguring or AddDbContext |
ObjectContext | Not supported - use DbContext |
EntityObject | POCO entities only |
Code First Migrations | EF Core Migrations (similar syntax) |
// EF6
public class LegacyContext : DbContext
{
public LegacyContext() : base("DefaultConnection") { }
public DbSet<Product> Products { get; set; }
}
// EF Core
public class ModernContext : DbContext
{
public ModernContext(DbContextOptions<ModernContext> options)
: base(options) { }
public DbSet<Product> Products { get; set; }
}
// Registration in Program.cs
builder.Services.AddDbContext<ModernContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
| Legacy Package | Modern Replacement |
|---|---|
System.Web | Microsoft.AspNetCore.* |
System.Web.Mvc | Microsoft.AspNetCore.Mvc |
EntityFramework | Microsoft.EntityFrameworkCore |
Microsoft.Owin | Built-in middleware |
Newtonsoft.Json | System.Text.Json (or keep Newtonsoft) |
log4net / NLog | Microsoft.Extensions.Logging + provider |
Unity / Ninject | Built-in DI container |
IHttpContextAccessorIConfiguration injectionIWebHostEnvironment.ContentRootPath