Converting a .NET MVC Application to .NET Core

Web Development

In this blog post, we will discuss how to convert a .NET MVC application to .NET Core. To follow along you'll need to install an appropriate version of Visual Studio and .NET Core.

MIGRATING TO .NET CORE

Converting a .NET MVC Application to .NET Core.

In this blog post, we will discuss how to convert a .NET MVC application to .NET Core. To follow along you’ll need to install an appropriate version of Visual Studio and .NET Core.

Here is a rough outline of the process:

  • Create a new empty .NET Core application.
  • Copy existing files and folders from the .NET MVC application into the new Core application.
  • Update all packages and dependencies to .NET Core compatible versions.
  • Configure and build the application.
  • Test the application to ensure all features work as expected.

Let’s get started!

Create a new empty .NET Core application

Start off by opening Visual Studio and creating the new project which will serve as the base of your migrated application. Choose the ASP.NET Core Web Application template and make sure you select the Empty template. We will be copying over all the existing files and folders from the .NET MVC application, so we don’t need any of the default files that come with the Empty template.

Copy existing files and folders

Now that we have the new empty project created, we can start copying over all of the files from the .NET MVC application. Simply copy the files and folders from the MVC application into the new Core project. One important thing to note is that the folder structure in .NET Core is slightly different than in .NET MVC. In particular, the wwwroot folder is used for static files such as images, CSS, and JavaScript. So, you’ll need to move any static files from the MVC project into the wwwroot folder in the Core project. Controllers and views however can stay in their respective folders.

Update packages and dependencies

The next step is to convert all packages and dependencies to .NET Core compatible versions. Today almost all packages have a .NET core compatible version, and they should be easy to find on NuGet. You may just need to remove and re-add each package that the compiler complains about.

Some things that were part of the .NET Framework previously have been moved to NuGet packages in .NET Core, sometimes with new syntax. This could break existing code and necessitate finding and installing new packages. This will need to be evaluated on a case by case basis, but usually you can find a fix by searching online for the method that is now missing along with ‘.NET Core’.

And you may also find yourself in a situation where an old package was never updated to .NET Core and won’t work with your application anymore. This is the worst-case scenario and means that you need to instead find another library that will replace the existing library.

Configure and build the application

Once all the files have been copied over and the packages have been updated, the next step is to configure the application and build it. This includes adding any missing configuration settings and updating any existing ones to work with .NET Core. After the application has been built, it can be run and tested to make sure everything is working as expected. If you have any automated tests, they should also be run at this time to make sure that the application still works as expected after the conversion.

Test the application

Finally, it’s time to test the application to ensure all features work as expected. This is especially important if you are migrating an existing application with users. Start by testing all the basic functionality to ensure pages render correctly and data is displayed correctly. Then, move on to more specific functionality like form submission, file uploads, etc.

If you are migrating an existing database, it’s also a good idea to run some tests to ensure data is being migrated correctly. Once you are confident that the application is working as expected, you’re ready!

Get In Touch