Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply EF migration on publish available only for some web projects

I've got several projects using Asp.Net Core 1.0 and Entity Framework Core 1.1.0

I have a code first migration approach and I publish to Azure through Visual Studio 2015.

The way I used to apply migrations in Azure Sql Server was by enabling a checkbox on publish: "Entity Framework Migrations - Apply this migration on publish", where I typed in a connection string.

I updated several packages and now for one of my projects I don't see this option to apply migrations on publish anymore. I can see that it tries to discover data contexts but it does not find anything (although it's there in the same project..)

See below:

  • Project where I can apply migrations on Azure when publishing: apply migrations available

  • Project where the option to apply migrations on Azure when publishing is gone: apply migrations not available

I suspect it has something to do with some dependency version for the project and not with my IDE because I am using the same Visual Studio (2015 update 3) for both projects.

I couldn't find information about this. What dependency allows this option? If I find out what version is problematic then the remaining question is how to apply migrations when publishing then?

Both projects have the migrations in the Web project and both projects are using "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0"

UPDATE 1: I managed to find what's involved in this. It seems that if I use these dependencies:

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"

Visual studio is able to find data context and offer the option to Apply migrations on publish. But if I use newer versions of those dependencies like:

"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0"

Then that option to apply migrations is gone and VS cannot find any data context when publishing.

I'd need to find out what's the latest status with the migrations thing and Asp.Net Core.

like image 825
diegosasw Avatar asked Oct 18 '22 20:10

diegosasw


1 Answers

I have stumbled upon a very similar problem (Publishing fails to look for data contexts within the project to publish) within Visual Studio 2017 after creating an empty ASP.NET Core Web API project and adding migrations.

In order to make it work, I have included the following lines within the .csproj file:

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
like image 172
Alexei - check Codidact Avatar answered Oct 21 '22 05:10

Alexei - check Codidact