Migrating to .NET Core and Beyond
Tags: dotnet, csharp
Published: 2020-01-13 04:57:26

---
title: Migrating to .NET Core and Beyond
published: true
date: 2020-01-13 04:53:04 UTC
tags: Dotnet, csharp
cover_image: https://i1.wp.com/killalldefects.com/wp-content/uploads/2020/01/Migration.png?fit=768%2C323&ssl=1
canonical_url: https://killalldefects.com/2020/01/12/migrating-to-net-core-and-beyond/
---

Let’s discuss the various flavors of .NET and outline the need and options available for migrating from .NET Framework to .NET Core and eventually .NET 5.

## The Flavors of .NET

Current discussions of .NET center around the following 3 buckets of technologies:

- .NET Framework
- .NET Core
- .NET Standard
- .NET 5 (Sometimes referred to as “DotNext”)

Not included in this list are one-off dialects like Xamarin, UWP, and Silverlight which tend to rely on subsets of other versions.

.NET Framework refers to everything from the initial release of .NET to the latest patch of .NET Framework 4.8. All of these are based on the same types of base class libraries.

.NET Core refers to the cross-platform modernized rewrite of the .NET Framework. It is a subset of .NET Framework and doesn’t support some features in .NET Framework. Web Forms is likely the clearest example of an unsupported technology, but other things that rely on Windows-native APIs or are deprecated were not ported over to .NET Core.

.NET Standard refers to class libraries which can be referenced by either .NET Core or .NET Framework projects. This limits the amount of things they can rely on, but offers a good gradual migration strategy for your applications.

.NET 5 is the upcoming next major version of .NET Core. Dropping the “Core” signifier is part of the clear signifier that .NET Framework is entering a long term support phase and .NET Core / .NET 5 will be getting the attention and updates from here on out.

## What does this mean for .NET Framework?

My expectation is that .NET Framework will receive only critical maintenance patches and continue to receive LTS support, but will become less and less relevant over time.

This means, that if you want your applications to benefit from future work Microsoft does with its technologies and platforms, you need to be moving to .NET Core / .NET 5.

## Migrating to .NET Core / .NET 5

Let’s take a look at a typical .NET Framework web application and discuss some migration strategies for it.

![](https://i0.wp.com/killalldefects.com/wp-content/uploads/2020/01/image-6.png?resize=175%2C300&ssl=1)

This is a traditional ASP .NET web application using Web Forms and .NET Framework. It consists of pages in web forms format and various classes to represent models and service logic. It also holds application configuration via its web.config file.

In order to migrate off of .NET Framework, we’re going to have to make this web application much smaller in scope in order to achieve our objective.

### Introducing a Class Library

Thankfully, we can create a new .NET Standard class library and move non-UI and non-web API classes from our web application into this class library. This significantly shrinks the number of responsibilities our web application project has on its own.

Additionally, by doing this in .NET Standard, we expose any dependency issues in the form of libraries those classes relied on now and can resolve them ahead of moving off of .NET Framework.

Since our class library is in .NET Standard, our .NET Core and .NET 5 projects will be able to reference it and use the logic in it.

![](https://i1.wp.com/killalldefects.com/wp-content/uploads/2020/01/image-7.png?w=770&ssl=1)

## Platform Extensions

In the case where you rely on libraries that are native to Windows and are not yet ready to migrate off of them, you can temporarily use Microsoft’s [Platform Extensions](https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/connect/net-introducing-the-windows-compatibility-pack-for-net-core) which were designed to provide environment-specific functionality and make migration a little easier.

## Migrating to MVC / Razor

Since .NET Core does not and currently _is not planned to_ support Web Forms, we’ll need to cut over our individual pages to MVC controller classes and Razor views.

Thankfully you can do this gradually as .NET Framework web applications can [support both MVC / Razor and Web Forms in the same project](https://www.red-gate.com/simple-talk/dotnet/asp-net/mixing-web-forms-and-asp-net-mvc/).

![](https://i2.wp.com/killalldefects.com/wp-content/uploads/2020/01/image-8.png?w=770&ssl=1)

_Note that instead of doing this gradually, you could move directly to .NET Core or .NET 5 and rewrite these pages as Blazor views._

## Taking Inspiration from Domain Driven Design

Web apps are large and converting them all typically a fairly massive undertaking. If this is the case in your project, you may want to consider following domain driven design principles and identifying related contexts and silos of pages and classes that could be split out to a new micro-front end.

While this is not something I am qualified to talk significantly amount at this point, pulling multiple smaller .NET Core applications out of a larger .NET Framework application could help you reach your target faster, though introduce challenges as far as authentication and state management goes.

## Completing the Migration

Assuming that you have a .NET Framework web application with only razor pages in it, you can take the last step of the migration and port the main web application.

There’s no direct option to migrate a project so what you’ll have to do is create a new .NET Core application and then move your razor views and controllers over to that project.

You will also need to migrate any application-specific configuration options to use the Startup and ConfigureServices methods in .NET Core and the appsettings.json file for state management.

Thankfully, these aspects of .NET Core are very minimal and simple and you should not need a large degree of code to do this.

Once all is ready, you can reference your class libraries and add any relevant NuGet packages, then compile and run your web application.

## What about .NET 5?

Since .NET 5 is a natural evolution of .NET Core, the migration path should be very simple once you’re on .NET Core to begin with.

.NET 5 releases at the end of 2020 and preview resources and tutorials will become more readily available as we get closer, but your main battle is going to be getting away from .NET Framework and onto .NET Core. Once on .NET Core, .NET 5 should be just as simple as a version upgrade.

## Closing Thoughts

Moving to .NET Core is a massive amount of work in many projects, but we as a community have to face the fact that Microsoft is committed to the future and next versions of the platform and these plans simply do not include Web Forms or even the older .NET Framework technologies.

[I love .NET](https://killalldefects.com/2019/09/23/a-love-letter-to-net/), but it’s time to accept that Framework’s time is waning and it is time to move on to .NET Core and .NET 5. Thankfully, there are migration options available – they just might take a heroic level of work over a long period of time.

* * *

_Cover Photo by [Gareth Davies](https://unsplash.com/@gdfoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/migrate?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)_

The post [Migrating to .NET Core and Beyond](https://killalldefects.com/2020/01/12/migrating-to-net-core-and-beyond/) appeared first on [Kill All Defects](https://killalldefects.com).