'Add Migrations to a class Library

I have a class library that contains my DBContext class and the entity classes.

I am using the class library as a nuget package in other projects - not in the same solution.

My plan is to be able to run migrations from the projects and let the migrations be stored in the context class Library under a folder names "Migrations".

So, after including the nuget package into the web project, i modify my Startup.css as follows:

 services.AddDbContext<MyDbContext>(options => options
        .UseSqlServer(Configuration.GetConnectionString("MyDbConnection"), m=>m.MigrationsAssembly("MyDbContextLibrary.Migrations")));

When I run this, I get the error message as follows

Could not load file or assembly 'MyDbContextLibrary.Migrations, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

I wish to get a guide on how to go about this.

What I am trying to achieve is such that all the migrations are contained in the DBContextLibrary so that any other project that includes it will have the migrations and can easily just run the "Update-Database" command without having to create separate migrations and another database. The plan is that all the projects can connect to the same database without having each project create their own database.

The project is running on EFCore 5.13 and ASP.Net Core 5

Please note, I already referred to the following SO questions and answer but yet to get a solution

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source