Search code examples
c#azureentity-frameworkasp.net-core-mvc

ASP.NET Core Project - Publish doesn't show the "Database Migrations" option


My project used to work perfectly for .NET Core 1.0, but moving to 1.1 is causing me days of headache!! I've been using Microsoft Azure for publishing and hadn't had too many problems.

I think I'm down to just the database migrations. I've been using migrations for quite a while now, but when I publish, I don't get the option to 'Apply this migration on publish'.

I have a second project that's working just fine. When I open up the publishing screen, an icon spins saying 'Discovering Data Contexts...' and then changes to 'Entity Framework Migrations'.

But for the life of me, I can't get it to work with my main project!!

What could be preventing the 'Entity Framework Migrations' from appearing while publishing?

I've done add-migration Init and update-database and those work perfectly locally, but not when trying to publish

My ApplicationDbContext.cs is just a default, and works with the other project.

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options){
    }

dotnet --info

 .NET Command Line Tools (1.0.0-preview2-1-003177)

And when I run locally, I can delete the SQL Database and Migration puts it back when I start. So I know Migration is working properly. I just can't get the option to show up during publish.

Thanks!!


Solution

  • I just hit this issue, the 'Discovering Data Contexts...' spinner ran for a bit and then I didn't get the 'Entity Framework Migrations' option at all.

    What fixed it for me was recreating the publish profile as follows:

    From the Publish screen press the Create new profile link: Publish to Azure screen

    And then change to the Select Existing option:

    Publish Select Existing

    Then pick your existing App Service

    enter image description here

    Once I did that, the 'Entity Framework Migrations' section showed up as expected in the Publish tool's Settings.

    For info, recreating the publishing file doesn't seem to have made any major changes in the .pubmxl file. The only changes were resourcegroups was changed to resourceGroups in the <ResourceId> setting, and <PublishFramework /> was changed to <PublishFramework></PublishFramework>. Neither of those seem likely to be the cause of the issue.