EF Core Tip 1: Running your migrations when publishing

I was looking for a way to automatically update the database after a deploy. The only way I found so far to do this, is to do this in code in your Startup class.

In the Configure method, use this code to upgrade your database other than Development:

if(!env.IsDevelopment())
{
    db.Database.Migrate();
}

If you make sure to set the correct environment variable in the environment you’re deploying to, it will upgrade the database with your migrations.

ASP.NET Core Tip 1: Setting the environment in an Azure App Service

In ASP.NET Core there is a great new way to indicate what environment your site is running on. An environment variable has been introduced called ASPNETCORE_ENVIRONMENT. You can find the official documentation here.

Here’s how you set the environment on an Azure App Service. Select the App Service you want to configure, and scroll down to Application Settings.

Under the section App Settings, you can add or update the ASPNETCORE_ENVIRONMENT setting to the correct value. Here it is configured to have Staging as the value.