Why and How to Migrate to .NET Core
In this article
You should migrate to .NET Core (now called .NET 5 and later) because it is the modern, cross-platform, and actively maintained successor to .NET Framework, offering better performance, flexibility, and long-term support. The migration process involves assessing your current codebase, updating project files, replacing framework-specific APIs, and testing thoroughly—here’s exactly how to do it step by step.
Background: .NET Framework vs. .NET Core
.NET Framework has been around since 2002, designed primarily for Windows. It is monolithic—the entire runtime is installed as a Windows component, and apps depend on that specific version. .NET Core, first released in 2016, was built from scratch to be modular, cross-platform (Windows, macOS, Linux), and open-source. In 2020, Microsoft unified .NET Core and .NET Framework into a single product called .NET 5, and since then, .NET 6, 7, and 8 have continued the line. The name “.NET Core” is still used colloquially, but the official name is just “.NET” (e.g., .NET 8).
Why migrate? The most concrete reasons:
- End of support: .NET Framework 4.8 is the last version—it receives security fixes but no new features. .NET Core/.NET gets regular major releases with new APIs and improvements.
- Cross-platform: Run your app on Linux containers, which is the standard for cloud deployments and drastically reduces infrastructure costs.
- Performance: .NET Core is significantly faster than .NET Framework in many benchmarks, especially for web workloads, thanks to a redesigned runtime and JIT compiler.
- Microservices and containers: .NET Core is designed for modern architectures—small, self-contained deployments that work with Docker and Kubernetes.
- Side-by-side versioning: You can run multiple .NET Core versions on the same machine without conflicts, unlike .NET Framework where only one version can be installed.
How Migration Works: The Core Differences
Before you start, understand the key technical differences that affect migration:
- Project file format: .NET Framework uses the old .csproj format with explicit file listings. .NET Core uses a simplified SDK-style project file that includes all files by default.
- Package management: .NET Framework relies on NuGet, but .NET Core uses PackageReference in the project file, which is cleaner and more manageable.
- API changes: Some APIs were removed or changed. For example,
System.Web(ASP.NET Web Forms) is not available; you must migrate to ASP.NET Core MVC or Razor Pages. - Configuration and dependency injection: .NET Core has a built-in dependency injection container and a new configuration system (appsettings.json instead of web.config).
Step-by-Step Migration Process
- Assess your current codebase: Use the .NET Portability Analyzer (a Visual Studio extension) to get a report of which APIs are missing or changed. This gives you a rough idea of the effort.
- Create a new project: In Visual Studio, create a new .NET Core project of the same type (e.g., class library, console app, ASP.NET Core web app). Copy your source files into it.
- Update project file: Replace the old .csproj content with the SDK-style format. Set the target framework (e.g.,
net8.0). Add NuGet package references using PackageReference. - Fix API calls: Search for common breaking changes. For example,
System.Drawingis not supported on non-Windows platforms—useImageSharporSkiaSharpinstead.HttpWebRequestis deprecated—useHttpClient. - Replace framework-specific libraries: Libraries that depend on
System.Webor Windows-only features need alternatives. For example, useSystem.Text.Jsoninstead ofNewtonsoft.Json(though you can still use Newtonsoft if you prefer). - Update configuration and startup code: Move from web.config/app.config to appsettings.json. In ASP.NET Core, replace Global.asax with the
Startupclass. - Test and refactor: Run your unit tests and fix any runtime issues. Pay special attention to file I/O paths (case sensitivity on Linux), culture settings, and threading.
- Deploy and validate: Deploy to a test environment, then to production. Use rolling deployments to minimize downtime.
Choosing the Right Target Version
As of 2024, the latest LTS (Long-Term Support) version is .NET 8, released in November 2023. LTS versions are supported for three years, while non-LTS versions (like .NET 7) are supported for 18 months. For a new migration, choose the latest LTS version to get the longest support window. If you have a large codebase, you might consider migrating to an intermediate version first (e.g., .NET 6) to reduce the jump, but it’s usually better to go straight to the latest LTS to avoid multiple migrations.
Common Problems and How to Solve Them
- Missing APIs: Some Windows-specific APIs (e.g.,
System.Drawing,Registry,Windows Services) are not available in .NET Core. Use cross-platform alternatives or platform-specific packages that implement them. - Third-party dependencies: Not all NuGet packages are compatible with .NET Core. Check the package’s target frameworks—if it only supports .NET Framework, look for a .NET Standard or .NET Core version, or find an alternative.
- ASP.NET Web Forms: This is the biggest hurdle for legacy web apps. You cannot migrate Web Forms directly—you must rewrite the UI using Razor Pages, MVC, or Blazor. This is a significant effort, so plan accordingly.
- Configuration and environment differences: Hard-coded paths, Windows-specific file paths, and case sensitivity can break on Linux. Use
Path.Combineand avoid hard-coded separators. - NuGet package restore issues: Sometimes packages fail to restore due to version conflicts. Use the
dotnet restorecommand and check for duplicate package references.
Costs and Risks of Not Migrating
Migrating has a cost: developer time, testing, and potential downtime. However, staying on .NET Framework has its own costs. You won’t get new features, performance improvements, or security fixes beyond critical patches. As cloud providers push Linux containers, you’ll be locked into Windows VMs, which are more expensive and slower to scale. Also, hiring developers who know .NET Framework is getting harder, as new talent learns .NET Core. The longer you wait, the larger the migration gap becomes.
Alternatives to Full Migration
If a full migration is not feasible, consider these options:
- Hybrid approach: Keep existing .NET Framework apps running while building new features in .NET Core, using shared libraries via .NET Standard (though .NET Standard is now superseded by .NET 5+).
- Use .NET Framework 4.8: It’s the last version and will receive security updates until at least 2029, giving you time to plan.
- Containerize .NET Framework: You can run .NET Framework in Windows containers, which improves deployment consistency but doesn’t solve the underlying performance or cross-platform issues.
- Rewrite selectively: Identify the most critical or high-traffic modules and migrate those first, leaving the rest on .NET Framework until you can replace them.
Frequently Asked Questions
Is .NET Core the same as .NET 5/6/8?
Yes, .NET Core was renamed to .NET 5 in 2020. The name “.NET Core” is still used to refer to the cross-platform line, but the official name is just “.NET” with a version number.
Can I run .NET Framework and .NET Core on the same machine?
Yes, they are completely independent. .NET Framework is a Windows system component, while .NET Core/.NET is installed as a separate runtime. You can run both side-by-side without conflicts.
How long does a typical migration take?
It varies widely. A simple class library might take a day, while a large ASP.NET Web Forms app with many third-party dependencies could take months. The .NET Portability Analyzer gives you a percentage of API compatibility, which is a good starting estimate.
What is .NET Standard and do I need it?
.NET Standard is a formal specification of APIs that all .NET implementations must provide. It was used to create libraries that work across .NET Framework, .NET Core, and Xamarin. In .NET 5 and later, you don’t need .NET Standard—just target net8.0 and your library will work with any .NET 8 app.
Is there a tool that automates the migration?
There is no fully automatic tool, but Visual Studio’s “Port to .NET Core” feature (available for some project types) can help. The .NET Portability Analyzer and the dotnet migrate command (which is deprecated but still works for some cases) can assist. Most of the work is manual.
Will my existing NuGet packages work?
Many will, if they target .NET Standard or .NET Core. Check the package’s dependencies in NuGet—if it only targets .NET Framework, you may need to find an alternative or use a compatibility shim like Microsoft.Windows.Compatibility (which adds many Windows-specific APIs).