1

There are the two projects in my solution: the first (Web) has the Startup class and the second (Db) has DbContext. I want migrations'd were placed in the Web project.

Db.ApplicationDbContext

    /* ApplicationUser is derived from IdentityUser */
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext(DbContextOptions options) : base(options) { }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        }
    }

Web.Program

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
}

Web.Startup.ConfigureSevices

    services.AddDbContext<ApplicationDbContext>(options => {
        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Web"));
    });

The CLI command Add-Migration First from the Web project returns

No DbContext was found in assembly 'Web'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic

Target framework is netcoreapp2.0, EF Core 2.x, AspNetCore.All 2.x (for Web)

How can I resolved it?

Ilya Loskutov
  • 1,967
  • 2
  • 20
  • 34

0 Answers0