📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Walk me through migrating a shared class library and an ASP.NET MVC 5 app from .NET Framework 4.8 to .NET 10. How do you convert to SDK-style projects, use multi-targeting so the old app keeps working, and what does the upgrade tooling do for you versus what you change by hand? Show the before and after.

Hands-on migration of a class library and an MVC 5 app to .NET 10: converting to SDK-style projects, multi-targeting net48 and net10.0, packages.config to PackageReference, Global.asax and web.config to Program.cs and appsettings.json, and where GitHub Copilot app modernisation helps.

Mid-Level Coding Intermediate aspnet-core aspnet-mvc5 copilot-modernisation legacy-migration multi-targeting sdk-style-projects

🎯 Key points

  • Convert libraries to SDK-style first (try-convert or by hand), packages.config to PackageReference
  • Multi-target libraries with <TargetFrameworks>net48;net10.0</TargetFrameworks> and #if or conditional items for differences
  • The MVC 5 app becomes a new ASP.NET Core project; controllers and views port, the pipeline does not
  • Global.asax events map to Program.cs middleware and services; web.config appSettings map to appsettings.json + IOptions
  • Replace System.Web types (HttpContext.Current, HttpRequestBase) with ASP.NET Core abstractions or System.Web adapters
  • Bundling, filters, model binding and routing differences need attention ([FromBody], attribute routes)
  • Copilot app modernisation automates project edits and suggests fixes; humans review and test
  • Run characterisation and integration tests on both targets in CI

⏱ 30-second answer

I go bottom-up. First the class library: convert it to an SDK-style project, move packages.config to PackageReference, and multi-target net48;net10.0 so the existing MVC 5 app keeps consuming it while the new app is built. Differences go behind #if NET or conditional package references.

The MVC 5 app can't be retargeted in place, because System.Web doesn't exist on .NET 10. I create a new ASP.NET Core project, move controllers and views across, and translate Global.asax into Program.cs middleware and services, and web.config into appsettings.json with options. GitHub Copilot app modernisation automates much of the project editing; I still review every change. The trade-off: multi-targeting doubles build and test time for a while, but it keeps production shipping throughout.

🗣 Full answer (senior)

How I would answer this in an interview

"I split this into two different jobs, because they are. The class library is a retarget: I convert the old verbose .csproj to SDK style, either by hand or with try-convert, move packages.config to PackageReference, and set <TargetFrameworks>net48;net10.0</TargetFrameworks>. Most code compiles unchanged. Where it doesn't, say it reads ConfigurationManager.AppSettings, I push that dependency out to the caller as an options object, or use #if NET as a short-term bridge. CI builds and tests both targets, so the existing MVC 5 app can keep consuming the library from the same commit.

The MVC 5 app is not a retarget, it's a port. ASP.NET Core has no System.Web, no Global.asax, no HttpModule pipeline. So I create a new ASP.NET Core project, bring controllers and Razor views across, which mostly survive with small changes, and rebuild the plumbing: Application_Start becomes service registrations in Program.cs, Application_BeginRequest and HTTP modules become middleware, filters move to the MVC options, and web.config app settings become appsettings.json bound to options classes. For a big app I'd do this route by route behind YARP rather than in one go.

On tooling, GitHub Copilot app modernisation in Visual Studio now does the project conversion and proposes code fixes; the old Upgrade Assistant is deprecated. The mistake I see is trusting the tool's green build: model binding, JSON casing and filter order all change behaviour without a compile error. Tests on both runtimes are what make this safe."


Legacy to modern: the mapping

MVC 5 / .NET Framework ASP.NET Core on .NET 10
Global.asax Application_Start Program.cs builder + app pipeline
RouteConfig.RegisterRoutes app.MapControllerRoute / attribute routing
FilterConfig / GlobalFilters AddControllersWithViews(o => o.Filters.Add(...))
BundleConfig (System.Web.Optimization) Static files + a front-end build, or MapStaticAssets()
HTTP modules / handlers Middleware / endpoints
web.config <appSettings>, <connectionStrings> appsettings.json, user secrets, Key Vault, IOptions<T>
HttpContext.Current HttpContext in controllers, IHttpContextAccessor sparingly
Unity / Autofac container Built-in DI (Autofac still works if needed)
packages.config <PackageReference>
ApiController (Web API 2) ControllerBase + [ApiController]

What the tooling does vs what you do

Task Tool You
SDK-style conversion, PackageReference Automated Review conditional items, remove dead references
Retarget, package upgrades Automated with suggestions Choose replacements, test behaviour
Create ASP.NET Core project, copy controllers/views Partly automated Rebuild pipeline, auth, config, DI
System.Web call sites Suggestions Design: adapters, DI or refactor
Behaviour parity Not covered Characterisation and integration tests

Production example

For an internal claims app with 6 libraries and one MVC 5 site, the libraries were multi-targeted in two weeks with no production change. The web port went route by route over three months behind YARP; p95 latency on the migrated routes dropped from 410 ms to 160 ms, and memory per instance fell by about 40%.

🔍 What the interviewer is checking

Checks hands-on familiarity with the actual mechanics of migrating projects and the MVC pipeline, not just the strategy.

Green flags

  • Knows libraries are retargeted but the web app is ported
  • Shows concrete Global.asax and web.config to Program.cs and appsettings.json mappings
  • Uses multi-targeting and conditional compilation correctly
  • Mentions behaviour differences (JSON casing, binding) and tests on both runtimes

Red flags

  • Thinks changing TargetFramework is enough for the web app
  • Puts secrets into appsettings.json
  • Relies only on the tool with no testing

📚 Learn in depth

1. Old-style vs SDK-style projects

Old .csproj files list every source file, every reference with a HintPath, and import MSBuild targets by path. SDK-style projects use globbing and implicit imports, so a 400-line file usually becomes 15 lines.

Old style                          SDK style
------------------------------     ------------------------------
<Project ToolsVersion="15.0">      <Project Sdk="Microsoft.NET.Sdk">
<Compile Include="A.cs" /> x 300   (globbed automatically)
packages.config + HintPath         <PackageReference Include=... />
AssemblyInfo.cs                    Generated from properties

Web Application Projects (MVC 5) can't be fully SDK-style on .NET Framework without community SDKs, which is one more reason the web app is a new project rather than a conversion.

2. How multi-targeting works

With <TargetFrameworks>net48;net10.0</TargetFrameworks>, MSBuild runs an inner build per target. Each defines symbols: NET48, NETFRAMEWORK, NET10_0, NET, NET5_0_OR_GREATER and so on. You can vary code (#if NETFRAMEWORK), package references (Condition="'$(TargetFramework)' == 'net48'") and compile items. NuGet packs both into one package under lib/net48 and lib/net10.0.

          Domain.csproj
         /             \
  inner build net48   inner build net10.0
        |                    |
  bin/net48/Domain.dll  bin/net10.0/Domain.dll
        |                    |
  MVC 5 app (net48)     ASP.NET Core app (net10.0)

3. Why the web app is a port, not a retarget

MVC 5 runs inside IIS's integrated pipeline via System.Web.HttpApplication. ASP.NET Core is a self-hosted pipeline (Kestrel, optionally behind IIS via the ASP.NET Core Module). The request object model, configuration system, DI and hosting all differ. Controllers and Razor views are the parts that carry across, with changes:

  • ActionResult types mostly survive; HttpStatusCodeResult becomes StatusCodeResult.
  • [FromBody] is inferred for complex types under [ApiController].
  • Html.Partial becomes <partial> or Html.PartialAsync.
  • Child actions become view components.
  • JSON defaults move from Newtonsoft (PascalCase) to System.Text.Json (camelCase).

4. Incremental ports

For anything non-trivial you put YARP in the new ASP.NET Core app, proxy everything to the old site, and move routes one at a time. System.Web adapters let shared code keep using System.Web.HttpContext-style APIs during the transition, and remote session/authentication share state with the old app.

5. Testing on both runtimes

Run the test project multi-targeted too (net48;net10.0) so the same tests prove both builds. For the web app, WebApplicationFactory<Program> integration tests should record responses from the old app (golden files) and compare.

Try it yourself

  1. Convert an old class library with dotnet tool install -g try-convert and try-convert -p Domain.csproj; diff the result.
  2. Multi-target it and add a method that uses #if NETFRAMEWORK; inspect both DLLs with dotnet pack output.
  3. Port one MVC 5 controller and view to a fresh dotnet new mvc app and list every change you needed.
  4. Compare JSON output of the same model on Web API 2 and ASP.NET Core; fix casing with JsonSerializerOptions.
  5. Write a WebApplicationFactory test that asserts the ported route returns the same HTML fragment as the old one.

💻 Code

Before and after: Global.asax plus web.config versus Program.cs plus appsettings.json.

// BEFORE: Global.asax.cs on .NET Framework 4.8 (MVC 5)
public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        UnityConfig.RegisterComponents();
    }

    protected void Application_BeginRequest()
    {
        // Correlation id read from a header and stashed in HttpContext.Items
        HttpContext.Current.Items["CorrelationId"] =
            Request.Headers["X-Correlation-Id"] ?? Guid.NewGuid().ToString();
    }
}
// AFTER: Program.cs on .NET 10
using Contoso.Claims.Web;

var builder = WebApplication.CreateBuilder(args);

// web.config <appSettings> -> appsettings.json section, validated at start-up
builder.Services.AddOptions<ClaimsOptions>()
    .Bind(builder.Configuration.GetSection("Claims"))
    .ValidateDataAnnotations()
    .ValidateOnStart();

// FilterConfig -> MVC options; UnityConfig -> built-in DI
builder.Services.AddControllersWithViews(o => o.Filters.Add<AuditFilter>());
builder.Services.AddScoped<IClaimService, ClaimService>();

var app = builder.Build();

// Application_BeginRequest -> middleware
app.Use(async (context, next) =>
{
    context.Items["CorrelationId"] =
        context.Request.Headers["X-Correlation-Id"].FirstOrDefault() ?? Guid.NewGuid().ToString();
    await next(context);
});

app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
app.Run();

namespace Contoso.Claims.Web
{
    public sealed record ClaimsOptions
    {
        [System.ComponentModel.DataAnnotations.Range(1, 365)]
        public int MaxClaimAgeDays { get; init; } = 90;
    }
}
// web.config <add key="MaxClaimAgeDays" value="90" /> becomes:
{
  "Claims": { "MaxClaimAgeDays": 90 },
  "ConnectionStrings": { "Claims": "set in user secrets or Key Vault, never here" }
}

The shared library, multi-targeted, with one bridging difference:

namespace Contoso.Claims.Domain;

public sealed class ClaimPolicy(int maxClaimAgeDays)
{
    // Configuration is passed in, so the library no longer calls ConfigurationManager
    public bool IsInTime(DateOnly lodged, DateOnly incident) =>
        lodged.DayNumber - incident.DayNumber <= maxClaimAgeDays;

#if NETFRAMEWORK
    // Bridge for the old app until it is retired
    public static ClaimPolicy FromAppSettings() =>
        new(int.Parse(System.Configuration.ConfigurationManager.AppSettings["MaxClaimAgeDays"] ?? "90"));
#endif
}

⚠ Common mistakes

  • Mistake: Trying to retarget the MVC 5 project to net10.0. Why it is wrong: System.Web doesn't exist on modern .NET, so it is a port, not a retarget. Instead: create a new ASP.NET Core project and move code across, ideally route by route, using System.Web adapters so shared code keeps compiling during the transition.
  • Mistake: Big-bang cutover of the whole web app. Why it is wrong: months without a release and one huge risky deployment. Instead: put YARP in front and migrate routes incrementally.
  • Mistake: Leaving ConfigurationManager calls inside shared libraries. Why it is wrong: they silently return null on .NET 10 when no app.config exists. Instead: pass settings in through constructors or options.
  • Mistake: Only running tests on net10.0. Why it is wrong: the old app still uses the net48 build and can regress. Instead: multi-target the test project and run both in CI.
  • Mistake: No contract tests on the HTTP surface. Why it is wrong: JSON casing, date formats, null handling and status codes change between Web API 2/MVC 5 and ASP.NET Core without a compile error, and JavaScript clients or partners break. Instead: record responses from the old app (golden files) and assert the ported routes return the same shape, status and headers.
  • Mistake: Copying connection strings from web.config into appsettings.json. Why it is wrong: secrets end up in source control. Instead: use user secrets locally and Key Vault with managed identity in Azure.
  • Mistake: Trusting the tool's green build. Why it is wrong: Copilot app modernisation (or the legacy Upgrade Assistant) edits projects and suggests fixes, but can't know your business behaviour; filters, model binding and routing behave differently at run time. Instead: review every generated change and prove behaviour with characterisation and contract tests.

🏛 Senior insight: trade-offs

The real decision is where to put the seam. Libraries are cheap to multi-target and give you a shared core; the web layer is expensive and is where incremental migration pays off. You can't retarget System.Web, but you don't have to port it all at once either: YARP in the new app forwards unported routes to the old one, and System.Web adapters (Microsoft.AspNetCore.SystemWebAdapters) let shared libraries keep using HttpContext-style APIs and share session and authentication with the old app while you move. I keep multi-targeting temporary, with an exit date, because two runtimes in CI is a tax.

On tooling: GitHub Copilot app modernisation is Microsoft's current assistant (it needs a paid Copilot plan); the legacy .NET Upgrade Assistant can still be enabled in Visual Studio, and try-convert handles SDK-style conversion. All of them save typing, none of them prove behaviour. I measure p95 latency, memory and error rate per migrated route against the old app before switching traffic.

Approach When it fits Cost When not to
Multi-target net48;net10.0 Library shared by old and new apps Double builds/tests Old app is retired within weeks
Retarget to netstandard2.0 Pure logic, no newer APIs needed Can't use modern APIs Library needs Span, new BCL types
New ASP.NET Core app + YARP + adapters Large MVC app, must keep shipping Proxy layer, shared auth Tiny app: port in one go
In-place port Small app, good tests One big release Business-critical with weak tests

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions converting to SDK-style projects Why: Checks they understand what SDK-style projects change
    How to answer

    An SDK-style project begins with <Project Sdk="Microsoft.NET.Sdk">. That one attribute pulls in all the standard build logic, so the file only holds what's specific to your project: the target framework, the output type, a few settings and its references. Source files are picked up automatically by globbing, so you don't list each .cs file. Packages are PackageReference items. Old-style .NET Framework project files listed every file, imported targets by hand and used packages.config. That made them long, noisy in merges and tied to Visual Studio on Windows.

  2. When: Candidate mentions System.Web, Global.asax or HttpContext.Current Why: Checks depth on what each System.Web concept maps to in ASP.NET Core
    How to answer

    Classic ASP.NET sits on System.Web.dll, which is bound to IIS and Windows. MVC 5 and Web API 2 were two separate frameworks: different controller base classes (Controller vs ApiController), filters, routing and DI hooks. App start-up lived in Global.asax, cross-cutting code in HttpModules, request data came from the ambient HttpContext.Current, and settings came from web.config.

    ASP.NET Core replaces all of that: one MVC framework for pages and APIs, Program.cs for start-up, middleware for modules, HttpContext passed explicitly (or IHttpContextAccessor), appsettings.json plus environment variables via the options pattern, and built-in DI. The trade-off: it is faster and cross-platform, but nothing in System.Web compiles against it unchanged.

  3. When: Candidate mentions multi-targeting a shared library Why: Checks they can manage the lifecycle of a multi-targeted package
    How to answer

    Multi-target in the .csproj (<TargetFrameworks>net48;net8.0;net10.0</TargetFrameworks>, or netstandard2.0;net10.0 if you need no Framework-only APIs), use #if NETFRAMEWORK sparingly, and let dotnet pack produce one lib/<tfm> folder per target. Run the test suite on every target in CI. Only target supported runtimes: .NET 6 and 7 are out of support, so the modern targets are the LTS releases (.NET 8 and .NET 10).

    Decide when to drop net48 from data, and review it regularly (for example each major release): NuGet download stats per framework, internal consumers' target frameworks, and support requests. Announce the removal a release ahead, and remove it in a major version because dropping a target is a breaking change.

🛠 Real-world problems: how you handle them

Multi-targeted library breaks the old MVC 5 site through ConfigurationManager
Situation
A [claims processing] system: one MVC 5 site on .NET Framework 4.8 and a new ASP.NET Core 10 app sharing a multi-targeted `Domain` library. [About 4,000 internal users] in [Australia East].
Signals
After a release, claims older than 90 days were accepted by the new app but rejected by the old one. No exceptions; a business user raised it after [two days]. Application Insights showed the same request producing different results per app.
Investigation
Compared the two code paths with characterisation tests. The library read `ConfigurationManager.AppSettings["MaxClaimAgeDays"]`; on .NET 10 there was no app.config, so it returned null and fell back to a hard-coded 365. Confirmed by running the same unit test on both targets.
Resolution
Immediate: set the value explicitly in the new app via an environment variable read through a small adapter. Real fix: removed `ConfigurationManager` from the library, passed `maxClaimAgeDays` in via options, and added `ValidateOnStart` so a missing value fails at start-up.
Prevention
Test project multi-targeted so every test runs on net48 and net10.0; a BannedApiAnalyzers rule banning `ConfigurationManager` in shared libraries; a migration checklist item for config access.

How to tell it (STAR)

**S:** We were migrating [a claims system] from MVC 5 to ASP.NET Core 10, with a shared library multi-targeted for both. **T:** Business users reported the two apps disagreeing on which claims were in time, and I owned the fix. **A:** I wrote a characterisation test, ran it on both targets and found the library reading `ConfigurationManager`, which silently returned null on .NET 10. I patched config in the new app the same day, then moved the setting to validated options passed into the library and banned `ConfigurationManager` in shared code with an analyser. **R:** Both apps agreed again within [a day], and the test suite now runs on both runtimes; we caught [three] similar issues before they reached production.

More in Migration Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me