ASP.NET Core 3.1 - Migrate From .NET Core 2.2
describes the migration of the ASP.NET Core 2.2 - Bootstrap Native Project to ASP.NET Core 3.1 which
included Identity and did not use an in memory database. This migration is similar with a few important
differences. The UseInMemoryDatabase option used in the Table Functions Project now requires the
Microsoft. EntityFrameworkCore. InMemory NuGet package.
Now use the Nuget Manager to install new packages. Right click on the project then click Manage NuGet Packages.
The Microsoft. AspNetCore. Mvc. NewtonsoftJson package is required for proper Details serialization. See
Migrate from ASP.NET Core 2.2 to 3.0 - Json.NET support.
The Microsoft. EntityFrameworkCore. InMemory package is required for the in memory database.
On the Browse tab, search and install the following packages:
Microsoft. AspNetCore. Mvc. NewtonsoftJson
Microsoft. EntityFrameworkCore. InMemory
Update the Program class to use IHostBuilder. The Table Functions Project uses a DataGenerator > Initialize
method after the build and before the run commands to seed the database. See
ASP.NET Core 2.2 - In Memory Entities.
Edit Program.cs, implement IHostBuilder:
public static void Main(string args)
//1. Get the IHost which will host this application.
var host = CreateHostBuilder(args).Build();
//2. Find the service layer within our scope.
using (var scope = host.Services.CreateScope())
//3. Get the instance of FoodDbContext in our services layer
var services = scope.ServiceProvider;
var context = services.GetRequiredService();
//4. Call the DataGenerator to create sample data
//Continue to run the application
public static IHostBuilder CreateHostBuilder(string args) => Host
// Set properties and call methods on options
Update the namespaces with using Microsoft.Extensions.Hosting;.
Use Find and Replace > Current Project to replace IHostingEnvironment with IWebHostEnvironment then update the namespaces with using Microsoft.Extensions.Hosting;.
Since I have been mainly using
Visual Studio 2019
and the 3.x SDK, I want to share a couple of methods I have found useful.
If you have installed more than one version of Visual Studio, double clicking the solution file may open the
solution in an older version. You can right click on the solution file, then Open with and select Visual Studio 2019.
I set the default Opens with to 2019 by right clicking the solution file, then Properties. The Change
button opens a dialog which allows you to select Visual Studio 2019.
Razor pages runtime compliation was included with the Microsoft. AspNetCore. App NuGet package. To enable the
runtime complilation for razor page edits without Microsoft. AspNetCore. App, you must install the
Microsoft. AspNetCore. Mvc. Razor. RuntimeCompilation
NuGet package and add the service to Startup.cs > ConfigureServices. I modified the .csproj file to only reference
the package and the ConfigureServices to only use AddRazorRuntimeCompilation for the Debug configuration. See
Razor file compilation in ASP.NET Core.