aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
258 stars 124 forks source link

Publish w/ Migrations from different dlls fail #898

Open rowanmiller opened 7 years ago

rowanmiller commented 7 years ago

Originally reported by @Allann on https://github.com/aspnet/EntityFramework/issues/7169

Steps to reproduce

Not sure how easy this will be, but:

  1. Have an ASP.Net Core website that has one or more DbContext referenced assemblies (Core dlls)
  2. Add the dbcontext in startup.cs (i.e: services.AddDbContext<MaintenanceContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Jbssa.FreightRates.Maintenance.Data")));)
  3. Publish the web app with the Entity Framework Migrations checked for those dbcontexts. In Settings tab of the Publish dialog. Ensuring the correct connection string is supplied.

The issue

Describe what is not working as expected.

Receive error in Error LIst in VS2015 U3. Error Your target project 'Jbssa.FreightRates.Web' doesn't match your migrations assembly 'Jbssa.FreightRates.Rates.Data'. Either change your target project or change your migrations assembly. Jbssa.FreightRates.Web 0

Error Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Jbssa.FreightRates.Web")). By default, the migrations assembly is the assembly containing the DbContext. Jbssa.FreightRates.Web 0

Further technical details

EF Core version: (found in project.json) "dependencies": { "Jbssa.FreightRates.Maintenance.Domain": "1.0.0-", "Jbssa.ApplicationData.Reference.Domain": "1.0.0-", "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0", "NETStandard.Library": "1.6.1", "Microsoft.AspNetCore.Http.Abstractions": "1.1.0", "System.Linq": "4.3.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", "Jbssa.Application.SharedKernel.Data": "0.1.0" },

"tools": { "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final" },

"frameworks": { "netstandard1.6": { "imports": "dnxcore50" } }

Operating system: Visual Studio version: VS 2015 Update 3 on Win10x64

Other details about my project setup: Structure: image Each BC_* project group are a DbContext and associated domain class. All are .Core class libraries.

rowanmiller commented 7 years ago

We suspect the issue is that the dotnet ef command call, that Publish calls to get the script, needs to specify --project to specify which project the migrations are in.

cc @bricelam

mlorbetske commented 7 years ago

/cc @vijayrkn

vijayrkn commented 7 years ago

@rowanmiller - For generating the sql script, we run the following command from the project working directly - dot ef migrations script --idempotent --output --context .

we don't currently pass the project name. Is there an EF command that exposes this info? If EF already knows about this, is it possible for EF to infer this info while generating the script?

jasonboninger commented 7 years ago

Running into this exact same issue. It sounds like publishing using the Entity Framework Migrations is not currently possible when migrations are in a different assembly, but would be a great feature to be able to take advantage of.

bricelam commented 7 years ago

Fixed with aspnet/EntityFramework#7741. Will be released as part of EF Core versions 1.0.4 and 1.1.2.