AI on Legacy .NET Code: Start With Tests, Not New Code
How to bring AI into a team on .NET Framework without growing the bug count: characterization tests for the existing code, automated PR review, instruction files for agents, and an upgrade pilot on one service with GitHub Copilot.
When a team with a long-lived .NET codebase gets an AI tool, the first thing everyone does with it is write new code faster. That is also where it is most dangerous. In code with no tests, every fast change is a change nobody really knows what it broke. The order that works is the reverse: first use the AI to build a safety net, and only then to change the code.
Why you don't start with features
The 2025 DORA report found that AI adoption is associated with higher delivery throughput, but also with a decline in delivery stability. Their explanation is direct: without control mechanisms such as strong automated tests, more changes lead to more instability. In .NET Framework code written a decade ago, with business logic inside WebForms code-behind and SQL queries inside controllers, there is almost no such control. Every PR the AI helped write reaches production with the same level of risk as hand-written code, only in greater volume.
I covered the broader picture in the article why AI didn't speed up your dev team. Here I focus on what you do inside the code.
Characterization tests: lock in what the code does today
Michael Feathers coined the term characterization tests in the book Working Effectively with Legacy Code. The idea is simple: before you change old code, you write tests that document what it actually does, including the odd behaviors. The test doesn't ask whether the result is correct, only whether it has changed.
This is exactly the kind of task the AI is good at. It reads a 400-line method faster than any developer, identifies branches, and suggests cases nobody would have thought to write. But it also errs in predictable ways, so the method is built in stages:
- Pick the code you're about to changeNot the whole system. The modules you'll touch in the coming months, or the ones that cause the most incidents.
- Ask the AI for tests of the existing behaviorThe prompt has to be explicit: document what the code returns today, don't fix it, and don't change production code to make it easier to test.
- Run them against the unchanged codeEvery test must pass on the current code. A failing test is either a mistake by the AI or behavior you didn't understand. Either way, find out before you continue.
- A developer reviews every testThis is the step you must not skip. The list below is what to check.
- A bug that turns up is documented, not fixedIf a test exposed wrong behavior, open a ticket for it. Fix it in a separate PR, so the tests reflect the existing state.
What I check in characterization tests the AI wrote:
- There is an assertion on a real valueA test that only verifies the result is not null always passes and locks in nothing. You need exact values.
- The thing under test isn't mockedAI tends to isolate too much, until the test tests the mock and not the code.
- The test is deterministicDates, time zones and CultureInfo are the usual source of tests that pass for one developer and fail on the build server. In systems that display dates and numbers in Israeli formats, this happens a lot.
- The name describes behaviorA name like CalculateDiscount_ReturnsZero_WhenCustomerIsInactive explains what is being locked in. Test1 doesn't.
- Production code didn't changeIf the AI changed code to make it easier to test, that is already refactoring, and the change should be reverted and done separately.
For code that depends on SQL Server or WCF services, it's usually better to start with integration tests against a test database, or at the level of the service contract, rather than trying to isolate every class. It's less elegant, but it gives you a safety net in the first week.
Automated PR review
Once you have tests, you add a second layer: automated code review on every PR. On GitHub you can set up a ruleset that automatically requests a review from Copilot code review, at the repo or organization level. If the code lives in Azure DevOps or another system, there are equivalent tools.
Automated review catches things a tired human reviewer misses, but it doesn't replace one. GitHub now also lets Copilot approve a PR and count that approval toward merge requirements. For legacy code without full test coverage, I recommend leaving the final approval with a person.
Instruction files: the context the tools are missing
DORA lists "AI-accessible internal data" as one of the seven capabilities that amplify the benefit of AI. In practice, the first step is an instructions file inside the repo. GitHub Copilot reads .github/copilot-instructions.md for general instructions, files in the .github/instructions folder for instructions on specific paths, and also AGENTS.md files. Copilot code review uses the same instructions.
The file doesn't need to be long. It needs to answer the questions every new developer asks in their first week:
# Repository instructions
- Solution targets .NET Framework 4.8. Do not suggest .NET 8 APIs.
- Build: msbuild Billing.sln /p:Configuration=Release
- Tests: NUnit, in tests/Billing.Tests. Run them before proposing a change.
- Data access goes through the repository classes in src/Billing.Data.
Never write inline SQL in pages or controllers.
- Never edit web.config transforms for production.
- Money is decimal, never double. Dates are stored in UTC.
Every line in a file like this saves an explanation someone would otherwise have to repeat in every conversation with the tool. And it serves the new developers on the team, too.
An upgrade pilot: one service, not the whole system
Only once you have tests and controls does an upgrade become a reasonable risk. In May 2025 Microsoft launched GitHub Copilot app modernization for .NET upgrades in preview, and the tool reached GA in September 2025. In November 2025 support was extended to upgrading web apps from .NET Framework to modern .NET in Visual Studio. In Microsoft's current documentation the agent is called GitHub Copilot upgrade.
According to the documentation, this is what it does:
- Upgrade paths
- From any version of .NET Framework to .NET 8 and later, or to .NET Framework 4.8.1 for those who aren't ready to move yet.
- A staged process
- Assessment, plan and execution. Each stage is saved as a Markdown file under
.github/upgradesin the repo, and you can edit it before continuing. - Working in git
- The agent offers to open a new branch and creates a commit for each part of the process, so you can review every change, roll back, or pick only some of the changes.
- Tooling for legacy technologies
- Among others: server-side WCF to CoreWCF, EF6 to EF Core, Web Forms to Blazor Server, and web.config to the ASP.NET Core configuration system.
- Tests before the upgrade
- It can generate tests that lock in behavior before the upgrade, the same idea as characterization tests.
- Environments
- Visual Studio 2026, or Visual Studio 2022 from version 17.14.17, as well as VS Code, GitHub Copilot CLI and GitHub.com.
And what to know before you start. The agent requires a local git repo, and it doesn't work offline: it needs a connection to the internet and to GitHub Copilot's infrastructure. In organizations with an isolated network, that is a question for information security before any planning. Microsoft also states explicitly that its suggestions are not guaranteed to follow best practices, that it won't catch every edge case, and that you need to verify the result before production. It also doesn't set up CI/CD for you.
That is why the pilot is on one service. Here is how to choose it:
- Small, with few dependenciesA service library or an internal API, not the central application everything else depends on.
- It has tests around itIf it doesn't, write characterization tests first, as I described above. Without them there is no way to know the upgrade didn't change behavior.
- It has an ownerOne developer who knows the code and will review every change the agent suggests.
- It can be measuredHow long the upgrade took, how much manual intervention it needed, and how many incidents there were after deployment.
The numbers from the pilot are the real asset. Instead of estimating that migrating the whole system is "a year-long project", you have a measured time on a real service from your own code, and you can build a roadmap from it. The measurement itself is worth doing with the same method I described in the guide how to measure whether AI really sped up your team (in Hebrew).
So the order is: characterization tests, automated PR review, instruction files, and only then an upgrade pilot. It sounds slow, but each step shortens the next. If you want help with the process, read more about AI adoption.
Sources
- Wikipedia: Characterization test
- Google Cloud: Announcing the 2025 DORA Report
- Google Cloud: Introducing DORA's inaugural AI Capabilities Model
- GitHub Docs: Adding repository custom instructions for GitHub Copilot
- GitHub Docs: Configuring automatic code review by Copilot
- Microsoft .NET Blog: Accelerate Your .NET Upgrades with GitHub Copilot (May 2025)
- GitHub Changelog: GitHub Copilot app modernization is now generally available for Java and .NET (September 2025)
- Microsoft Learn: GitHub Copilot upgrade overview
- Microsoft Learn: .NET upgrade scenarios and skills
- Microsoft Learn: GitHub Copilot upgrade FAQ
- Microsoft Tech Community: Explaining what GitHub Copilot modernization can and cannot do
Frequently asked questions.
- What are characterization tests?
- Tests that document what the code actually does today, not what it is supposed to do. The term was coined by Michael Feathers in the book Working Effectively with Legacy Code. They give you a safety net before a change, manual or AI-made, touches code that has no tests.
- Can you trust tests that the AI wrote?
- Only after a developer has reviewed them. The AI is very fast at writing the skeleton and covering cases, but it also tends to write tests that pass without checking anything. Human review is part of the method, not an optional step.
- Can GitHub Copilot upgrade .NET Framework to modern .NET?
- According to Microsoft's documentation, the GitHub Copilot upgrade agent (launched as GitHub Copilot app modernization) supports upgrading from any version of .NET Framework to .NET 8 and later, including dedicated tooling for WCF, EF6 and Web Forms. Microsoft itself stresses that you need to verify the result before production.
- Does the tool work in an air-gapped environment with no internet?
- No. According to Microsoft's FAQ, the agent requires a connection to the internet and to GitHub Copilot's cloud infrastructure, and has no offline mode. In an organization with an isolated network, check this with information security before you plan a pilot.

