To build on old code in Visual Studio, first get the project compiling and running unchanged, pin it to source control, then modernize in small verified steps—typically by retargeting the framework, updating NuGet packages, and fixing compile errors one category at a time. The key condition is that you understand what the code is supposed to do before you change how it does it: a build that succeeds is not the same as an application that behaves correctly. The workflow below works whether you're inheriting a .NET Framework 4.x WinForms app, a decade-old ASP.NET Web Forms site, or a class library that hasn't been opened since Visual Studio 2015.

Start by establishing a working baseline

Old code fails in boring ways before it fails in interesting ones. Missing SDKs, retired workloads, broken package references, and hard-coded paths will all masquerade as "the code is bad" when the real problem is that the environment no longer matches the project.

Prerequisites before you touch anything:

The original Visual Studio version pinned in the repository's .vsconfig, global.json, or README—or a documented reason it's unavailable Access to the source control history, so every change can be reverted A working build on at least one machine, even if that machine is a VM with an old VS installation A list of external dependencies: databases, file shares, scheduled tasks, third-party services

Steps:

1: Clone the repository without modifying it. If it isn't under source control, create a new Git repository from the current files before making any edits—this is non-negotiable. 2: Open the solution in a Visual Studio version that matches the project's target. For .NET Framework projects, this is usually Visual Studio 2019 or 2022 with the ".NET Framework 4.x development" workload installed; for older ASP.NET and Windows Forms, the "ASP.NET and web development" and ".NET desktop development" workloads cover most cases. 3: Build the solution and record the actual errors. Distinguish missing-SDK errors from genuine compile errors; the first category is environmental. 4: Run the application, if it's runnable, and exercise the paths you'll be touching. Write down the current behavior—screenshots, sample outputs, log excerpts. 5: Check in a "known-good" tag or branch so you can always return to the original state.

Success check: the solution builds with zero errors and, if applicable, the application starts and performs at least one full user workflow end-to-end. If you can't get it running, document exactly which dependency is blocking you before proceeding.

Stop condition: if the project depends on a licensed component, an internal SDK, or a database you can't access, resolve that access first. Modernizing around a missing dependency produces a build that compiles but can't be validated.

Understand the code before you judge it

The instinct when you open a 12-year-old file is to rewrite it. Resist that. Old code often encodes business rules that aren't written down anywhere, and a rewrite that ignores them will "fix" the code while breaking the business.

Read for structure first:

Entry points. Where does the application start? Program.cs, Global.asax, Main, Startup, or a click handler. Trace from there. Data access. Look for direct SqlConnection usage, Entity Framework versions (EF6 versus EF Core matters enormously here), DataSets, or stored procedures. Old ADO.NET code with string-concatenated SQL is both a maintenance and a security concern worth flagging now. Configuration. web.config and app.config frequently hold connection strings, WCF endpoints, and app settings that must survive any migration. Third-party libraries. List every reference in the .csproj and in packages.config or PackageReference. Check which ones are no longer maintained.

A practical technique: run the code, set breakpoints on the methods you intend to change, and let the debugger show you which paths are actually hit. This turns guesswork into evidence. Note anything that looks like dead code but is reached only under rare conditions—those paths are exactly what a careless refactor destroys.

Retarget the project framework deliberately

Retargeting is the single most consequential change you'll make, and it's where most "how to modernize" attempts fail. Moving a .NET Framework 4.7.2 project to .NET 8 is not a version bump; it's a platform change with different APIs, different configuration models, and different library compatibility.

A staged path that limits risk:

1: Stay on the same platform first. If the project targets .NET Framework 4.5.2 or 4.6.1, those are out of support. Retarget to .NET Framework 4.8 within the same platform—right-click the project, choose Properties, change the Target Framework dropdown, and rebuild. This is a low-risk change that buys security updates without breaking anything. 2: Update the language version. In the project properties' Build tab, raise the C# language version incrementally. Newer compilers can catch real bugs (definite assignment, unreachable code warnings) without changing runtime behavior. 3: Consolidate packages before crossing platforms. Convert packages.config to PackageReference using Visual Studio's built-in migration (right-click packages.config in Solution Explorer, then "Migrate packages.config to PackageReference"). For solutions with many projects, the community MigrateToPackageReference tool is the usual choice; for a single project, do it by hand to keep control. 4: Only then consider .NET 8 or later. If the app is Windows-only and uses Web Forms, WCF server-side hosting, or Windows Workflow, staying on .NET Framework is often the correct answer—crossing platforms may mean a rewrite, not a migration.

What to expect: after retargeting within .NET Framework, you'll see warnings but usually few errors. After a cross-platform move, expect hundreds of errors, most of them clustered around three areas: configuration APIs (ConfigurationManager versus IConfiguration), WCF client usage (largely unsupported on modern .NET; System.ServiceModel packages cover some scenarios), and Windows Forms designer code (mostly compatible, with occasional gaps).

Success check: the retargeted project restores, builds, and passes whatever smoke tests you captured in the baseline step. If it compiles but the app misbehaves, the retarget went too far—revert and split it into smaller steps.

Update dependencies in a controlled order

Package updates cause more subtle breakage than framework retargeting, because breaking changes are often documented only in release notes.

Work in dependency order, not alphabetical order:

1: Test framework first. Upgrade xUnit, NUnit, or MSTest so you can run tests while you upgrade everything else. If there are no tests, write a handful of characterization tests around the code you're about to touch before you touch it—these lock in current behavior, even the behavior you consider wrong. 2: Leaf libraries with no dependents. Utility packages, JSON serializers, logging abstractions. Small blast radius. 3: Foundational libraries that others depend on. Dependency injection containers, ORMs, HTTP clients. These often require code changes in multiple projects. 4: Frameworks last. ASP.NET MVC version bumps, EF6 to EF Core, UI libraries.

Use Visual Studio's NuGet Package Manager (Tools > NuGet Package Manager > Manage NuGet Packages for Solution) to see all versions across the solution at once; mismatched versions of the same package across projects cause runtime binding conflicts that are miserable to diagnose.

Pitfalls specific to old code:

EF6 to EF Core is not an upgrade. It's a port. LINQ translation differs, lazy loading requires opt-in, and some queries will throw at runtime that compiled fine. Budget real time. Newtonsoft.Json to System.Text.Json changes serialization defaults: property naming, null handling, and date formatting all differ. Behavior changes here can silently break API contracts. ASP.NET Identity version jumps frequently require schema migrations. Autofac, Unity, and StructureMap have all changed registration APIs over time; check the migration guide for your specific version.

Error-checking pattern: after each package update, build and run the tests. One update per commit. If the build breaks, you know exactly which package caused it, and reverting is trivial.

Get the code under test before changing behavior

Adding tests to old code is hard because it wasn't designed to be testable—static methods, direct database calls, and constructor logic that does work make it awkward to isolate.

Start where you can:

Characterization tests. Capture current output for given input, warts and all. These aren't tests of correctness; they're regression detectors. Use them freely. Seam extraction. If a method calls DateTime.Now, wrap it in an injectable interface with a default implementation. Behavior is unchanged; testability improves. This is a small, reversible refactor. Integration tests against a real database are often faster to write than mocking legacy data access. Use a disposable local instance (LocalDB, a Docker container, or a test-specific schema) and accept that they're slower.

A common failure mode: teams write fifty characterization tests, all pass, and then the modernization breaks behavior anyway because the tests covered only the happy paths. Spend your test effort on the code paths you're actively changing, not the whole application.

Modernize in vertical slices, not layers

A layer-by-layer rewrite ("convert all data access, then all business logic, then all UI") means the application is partially migrated for months, which is exactly when urgent bug fixes force you to patch two versions of everything.

Vertical slices are safer:

1: Pick one user-facing feature or workflow. 2: Trace it end-to-end through the old code. 3: Replace or refactor that feature's implementation, using modern patterns—dependency injection, async/await, typed configuration—while the rest of the application carries on as before. 4: Validate against your characterization tests and a manual smoke test. 5: Ship it. Repeat.

This approach lets old and new code coexist, which Visual Studio supports well: within one solution you can have .NET Framework projects and modern .NET projects side by side, connected by project references or an interop boundary. A common intermediate state is an ASP.NET Core host that calls into existing .NET Framework class libraries through a process boundary or a shared package.

Running the old and new application in parallel behind a feature flag—routing some traffic or some users to the new path—lets you compare results before cutting over.

Modernize the build and toolchain without breaking it

Old solutions often carry build assumptions that only work on one developer's machine: hard-coded MSBuild paths, relative references to ....\lib\ folders containing DLLs checked in by hand, custom .targets files, and post-build scripts that copy files to fixed locations.

Inventory these before you change the build system:

Scan every .csproj for entries pointing outside the repository, post-build events, and custom targets. Check whether the solution uses .sln format or a newer solution filter. Look at any CI pipeline for pinned MSBuild versions or legacy build agents.

Then, in order:

1: Pin the SDK with global.json if the project targets modern .NET, so builds are reproducible across machines. 2: Move from packages.config to PackageReference (covered above), which removes the packages folder and makes restore deterministic. 3: Replace manual file copies with MSBuild items or NuGet-delivered content. Anything a developer must remember to copy is a build that will eventually fail. 4: Centralize shared properties in Directory.Build.props if the solution has many projects with duplicated settings.

If the project targets .NET Framework and you have no plans to move it, you may still want to build with msbuild from Visual Studio Build Tools or with the newer dotnet msbuild for SDK-style projects only; classic .csproj files still require MSBuild from the Visual Studio toolchain in most configurations. Verify on a clean machine or CI agent—this catches the "works on my machine" problems that hard-coded paths hide.

Decide whether to modernize, stabilize, or replace

Not every old application should be modernized. The decision depends on three variables: how much the code needs to change, how much of it you can't afford to break, and how long it needs to live.

Situation Sensible default Why
Actively developed, .NET Framework 4.8, no platform-specific dependencies Retarget to modern .NET incrementally Long-term support, security patches, modern tooling
Stable, rarely touched, heavy Web Forms or WCF server usage Stay on .NET Framework 4.8, patch dependencies, add tests Crossing platforms may cost more than the app is worth
Frequent access to sensitive data, concatenated SQL, unpatched dependencies Prioritize security fixes over version upgrades The biggest risk is a data breach, not an old framework
Hundreds of thousands of lines, extensive custom UI, no tests Stabilize and containerize; modernize only at the edges A full rewrite is a multi-year project with high failure rates
Small, well-scoped, heavily tested A fresh rewrite is often cheaper Modernization's overhead isn't worth it when the codebase is small

The honest trade-off: modernization preserves institutional knowledge and keeps the system running while you improve it, at the cost of slow, piecemeal progress and a codebase that's heterogeneous for a long time. A rewrite gives you a clean architecture, at the cost of a period where feature development halts and the new system will have to rediscover all those unwritten business rules.

For most teams inheriting aging but working code, incremental modernization within a stable platform is the choice with the least downside. I'd rather ship a .NET Framework 4.8 app with patched dependencies and real tests than an abandoned half-migration that has neither.

Handling the cases that don't fit the standard path

Windows Forms and WPF designer projects. These generally retarget within .NET Framework without drama. Moving to modern .NET (net8.0-windows) works for many WPF and WinForms apps but certain designer features, third-party control suites, and System.Configuration-dependent code need attention first. Check whether your UI control vendor publishes a modern .NET version—if not, that's often a hard stop.

ASP.NET Web Forms. There is no modern equivalent. Web Forms depends on IIS and System.Web, and none of that exists in ASP.NET Core. Your options are staying on .NET Framework 4.8 (which continues to receive security updates as part of the .NET Framework lifecycle) or rewriting the UI in ASP.NET Core MVC or Razor Pages. Do not let a modernization mandate push you into a rushed Web Forms rewrite; that's how projects die.

Windows Workflow Foundation. WWF server-side workflows don't run on modern .NET. If workflows are core to the application, you're on .NET Framework for the foreseeable future, or facing a workflow-engine replacement.

WCF clients. Client-side WCF is partially supported on modern .NET through the System.ServiceModel.* packages, but check your binding—NetTcpBinding with certain security modes and some WS-* configurations are not supported.

VB.NET projects. Visual Studio 2022 still supports VB.NET, including for modern .NET. Retargeting VB is broadly the same process, though some language features and library APIs differ in availability.

Mixed solutions referencing DLLs built elsewhere. If a project depends on a compiled DLL you can't rebuild, the target framework of that DLL constrains everything. A .NET Framework 4.0 DLL can't be referenced by an ASP.NET Core project without a compatibility shim. Locate the source or the vendor first.

Common failure modes and how to catch them early

"It compiles, so it works." Old code frequently relies on configuration, registry keys, or installed components that a fresh build machine lacks. Always test on a machine that isn't your development machine.

Silent runtime behavior changes from package upgrades. AutoMapper version bumps change mapping behavior; JSON serializers change property matching; caching libraries change key strategies. These produce subtle bugs that tests miss unless they exercise real paths.

Partial migration limbo. A solution where half the projects are .NET Framework and half are modern .NET can work, but only with a clear boundary strategy. Without one, you'll find yourself maintaining two build systems and two sets of dependencies indefinitely.

Cultural resistance to tests. The most common reason modernization stalls isn't technology—it's that nobody agrees the tests are worth writing. Frame characterization tests as insurance against the changes you're making, not as a quality crusade.

Overestimating dependency health. An abandoned NuGet package is a modernization blocker, not a footnote. Check the package's last release date and issue tracker before planning around it. If a critical library hasn't shipped since 2018, its next release will not fix your compatibility problems.

A useful checkpoint convention: every commit in a modernization effort should leave the solution in a state where it builds and the tests pass. If a commit doesn't meet that bar, it isn't finished. This keeps the repository always shippable and makes a rollback a matter of reverting one commit rather than untangling a week of entangled changes.

Practical checklist for the first week

Create or verify source control; tag the original state. Record the current build environment exactly: Visual Studio version, workloads, SDKs, NuGet package versions, database version. Reproduce the build on a second machine or clean VM. Run the application and capture current behavior for the workflows you'll touch. Convert packages.config to PackageReference and verify the build. Retarget to .NET Framework 4.8 if applicable; verify the build and smoke test. Upgrade test frameworks and write a first characterization test around your first target feature. Convert one user-facing feature end-to-end using modern patterns; verify with tests and manual checks. Document the boundary strategy for any mixed modern/legacy code before you ship it. Repeat feature by feature, one checkable commit at a time.

The overall arc is simple to state and slow to execute: understand the behavior, protect it with tests, change one layer of the stack at a time, and never let the repository sit in a state that doesn't build. Old code is not an obstacle to be cleared; it's a working system whose current behavior is your specification. Build on it the way you'd build on a foundation: you check what's underneath before you add weight, and you add weight in steps you can verify.