Modernising legacy .NET

Moving from .NET Framework to modern .NET, one piece at a time

6–9 minutes
1,408 words

The estate that still pays the bills

Plenty of business-critical software still runs on .NET Framework: ASP.NET MVC and Web API sites, Windows services, WCF endpoints and class libraries that have been extended for a decade or more. It works, the business depends on it, and nobody wants to stop feature work for a year to rewrite it.

.NET Framework 4.8 isn’t going away overnight. It remains supported for as long as it’s installed on a supported version of Windows. But it no longer gets new features. Modern .NET is where the performance work, language features, container support and cross-platform hosting go, and more and more libraries no longer target .NET Framework at all.

Modern .NET has its own clock, too. .NET 8 and .NET 9 reached end of support on 10 November 2026. .NET 10, the current Long Term Support release, is supported until November 2028. “Modernising” therefore means two jobs: getting off .NET Framework, and then keeping up with a release every November.

The good news is that neither job needs a big-bang rewrite. The approach below moves an estate across in small steps, with the system running in production all the way through.

Start with an inventory

Before changing any code, find out what you actually have:

  • Project types. Class libraries, console apps and Windows services usually move easily. ASP.NET MVC and Web API sites take more work. Web Forms has no direct equivalent in modern .NET, so those pages need rebuilding, for example in Razor Pages or Blazor.
  • Dependencies. Check every NuGet package and third-party DLL. Does it have a version for modern .NET, an alternative, or nothing at all?
  • Framework-only technologies. Look for System.Web, WCF services, .NET Remoting, AppDomains, Windows Workflow Foundation and anything that relies on the registry or the GAC. Each one needs a decision. WCF services, for example, can move to CoreWCF or be replaced with gRPC or REST.
  • The dependency graph. Map which projects reference which. You migrate from the bottom up: shared libraries first, applications last.

The result is a list of migration units, each with a rough size and a known blocker if it has one. It’s the code-level version of a gap analysis.

Step 1: Convert to SDK-style project files

Old-style .csproj files list every source file and carry hundreds of lines of build plumbing. SDK-style projects are short, include source files automatically, and are the format modern .NET expects. They also work with .NET Framework, so this step changes nothing at runtime and can be released on its own.

XML
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>

</Project>

Move packages.config to PackageReference at the same time. It’s a small, low-risk change that makes every later step easier to review.

Step 2: Multi-target the shared libraries

Once a library builds cleanly as SDK-style, have it target both frameworks:

XML
<TargetFrameworks>net48;net10.0</TargetFrameworks>

The same code now compiles for the old applications and the new ones. Where the frameworks genuinely differ, keep the difference small and in one place:

C#
public static class TextEncoding
{
    public static Encoding Legacy()
    {
#if NETFRAMEWORK
        return Encoding.GetEncoding(1252);
#else
        // Code pages aren't built in on modern .NET
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        return Encoding.GetEncoding(1252);
#endif
    }
}

If #if blocks start spreading through a library, treat that as a sign the code needs a proper seam instead.

Step 3: Put seams around framework-specific code

The hardest code to move is code that reaches directly into the framework: HttpContext.Current, ConfigurationManager.AppSettings and static helpers that call them from deep inside business logic. Hide those behind small interfaces, and the business logic stops caring which framework it runs on.

Before:

C#
public decimal GetDiscount(Order order)
{
    var rate = decimal.Parse(ConfigurationManager.AppSettings["LoyaltyRate"]);
    var userId = HttpContext.Current.User.Identity.Name;
    // ...
}

After:

C#
public interface ICurrentUser
{
    string Id { get; }
}

public sealed class DiscountSettings
{
    public decimal LoyaltyRate { get; set; }
}

public class DiscountService(ICurrentUser user, DiscountSettings settings)
{
    public decimal GetDiscount(Order order)
    {
        var rate = settings.LoyaltyRate;
        var userId = user.Id;
        // ...
    }
}

Each application supplies its own implementation of ICurrentUser and its own way of loading DiscountSettings, web.config in the old world and appsettings.json with the options pattern in the new. As a bonus, DiscountService can now be unit tested without a web server.

Step 4: Move the web application route by route

For ASP.NET sites, Microsoft documents an incremental migration built on the Strangler Fig pattern. A new ASP.NET Core application sits in front of the old one. It handles the routes that have been migrated, and forwards everything else to the .NET Framework site using YARP, Microsoft’s reverse proxy library.

C#
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddHttpForwarder();

var app = builder.Build();

app.MapControllers();

// Anything not handled above goes to the legacy ASP.NET site
app.MapForwarder("/{**catch-all}", app.Configuration["LegacyAppUrl"]!)
   .Add(endpoint => ((RouteEndpointBuilder)endpoint).Order = int.MaxValue);

app.Run();

Users see one site. Behind it, controllers move across one at a time, each released and tested on its own. The System.Web adapters help shared libraries that still use System.Web types, and can share session state and authentication between the two applications while both are running. When nothing is forwarded any more, the old site is switched off.

Step 5: Protect behaviour with tests

Legacy code often does more than anyone has written down. Before moving a piece of it, pin down what it does today with characterisation tests: tests that record current behaviour, rather than the behaviour someone thinks is correct.

C#
public class InvoiceCalculatorTests
{
    public static TheoryData<string, decimal, decimal> Cases => new()
    {
        { "GOLD", 1200.00m, 1080.00m },
        { "STANDARD", 1200.00m, 1200.00m },
        { "GOLD", 0.00m, 0.00m },
    };

    [Theory]
    [MemberData(nameof(Cases))]
    public void Total_matches_current_behaviour(string tier, decimal net, decimal expected)
    {
        var calculator = new InvoiceCalculator();

        var total = calculator.Total(tier, net);

        Assert.Equal(expected, total);
    }
}

Run the same tests against both target frameworks. If a result changes after migration, you’ve found either a bug or an undocumented rule, and either way you’ve found it before your customers do.

A few common snags

  • Entity Framework. EF6 runs on modern .NET, so moving to EF Core can be a separate, later decision rather than part of the migration.
  • Configuration. web.config and app.config transforms don’t carry over. Plan how each setting moves to appsettings.json, environment variables or a secrets store.
  • Behaviour changes. Globalisation, default encodings and some serialisation behaviour differ between frameworks. This is where characterisation tests earn their keep.
  • Windows-only APIs. Code using the registry, Windows event log or System.Drawing may still run on modern .NET on Windows, but it ties you to Windows hosting. Decide whether that matters before you assume containers.

Tooling helps, but doesn’t decide

Microsoft has deprecated the .NET Upgrade Assistant in favour of GitHub Copilot app modernization, an AI agent in Visual Studio that analyses a solution, produces an upgrade plan and makes changes as a series of Git commits. It can take a lot of the mechanical work out of project conversion, package updates and API replacements.

It needs a paid GitHub Copilot plan, and like any AI output, its changes are a draft. The sequencing, the seams and the decisions about what to rebuild still need someone who understands the system. The tests from step 5 are how you check the tool’s work.

Small steps, always running

Modernising a .NET estate is the Strangler Fig pattern applied at the level of projects, packages and routes. Convert the project files, multi-target the libraries, add seams, move the web layer route by route, and let tests confirm nothing has changed. Each step can be released on its own, the business keeps running throughout, and the estate ends up on a platform with a supported future.

Adrian Ashdown

Solutions Architect working with .NET, SQL Server and cloud platforms. I write about architecture decisions and the trade-offs behind them.

More articles