Convert site from ASP.NET MVC to ASP.NET Core MVC

In this guide we will show you how you can convert an old site from ASP.NET MVC to ASP.NET Core MVC.
This guide assumes some familiarity with ASP.NET Core MVC.

This document is primarily based on Microsoft's guide to migrating from ASP.NET MVC to ASP.NET Core MVC.

Create a new ASP.NET Core Web Application

In our experience, the easiest way of converting a site to .Net Core is to create a new solution, and then copy over all the relevant bits and pieces from the old solution. This way we know exactly what's been brought over.

  1. Create a new ASP.NET Core Web Application that has the same namespace as your source project. This will make transferring the code files go a lot smoother.
  2. Delete the automatically generated files in wwwroot/, Models/, Views/, Pages/, and Controllers/ folders, if any.
  3. Install the Relatude.Core nuget package.
  4. Copy the Content.definition file from the source project root to the target project root.
    Go to the file's properties, and set 'Copy to output directory' to always.
    Open and save the Content.definition.
    (If you get an error, you probably have an old version of the Relatude Ontology Visual Studio extension installed. Uninstall the old one, quit VS, then install the newest version with the Relatude tool. The tool can be downloaded from the frontpage.)
  5. If you have a database in your source's 'App_Data'-folder, copy it to #target root#/WAF.Data/Content/Database
  6. At this point you should update your appsettings.json. It should look something like this:
    appsettings
  7. Now either copy over, or create controllers that match the ones in the source project.
  8. Copy over the view files from the source project.
  9. Copy over any other code files used.
  10. Update the usings and return values in all the code files and views. If any of the views are using ViewHelper-methods then these will have to be converted to ViewComponents or Partials or whatever you feel is most appropriate, since ViewHelper isn't supported in Core. 
  11. Update all calls to WAFContext (WAF.Presentation.Web.WAFContext) to instead use WAFNativeContext (WAF.API.Web.WAFNativeContext) injection.

    In a controller this would look like this:
    appsettings
    In a view, it would look like this:
    appsettings
  12. Copy over any static content. This should go in the wwwroot folder. You'll need to update all references to this content.
  13. If your old project uses a BundleConfig/BundleCollection for the static files, you can install the nuget package BundlerMinifier.Core, and create a bundleconfig.json in the target project root. If your old BundleConfig.cs file looks like this:
    appsettings
    Then your bundleconfig.json could look like this:
    appsettings
    And finally you'll need to update the references to your bundle(s).
  14. One of the last things to do is to update the Program.cs file with everything needed to get Relatude working.
    An example file could look like this:
    appsettings
    Note all the WAF-specific lines.
  15. Finally, for the moment, we need to add the following line to the (first) <PropertyGroup>-element in the .csproj file:
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>