Your target project [ProjectName] doesn't match your migrations assembly [AssemblyName]. Either change your target project or change your migrations assembly.
I am working on a project in ASP.NET Core 5.0, which contains a web application and the related class libraries. I use Entity Framework Core for data access. My DbContext class is in a class library project. When I run the add-migration command, I get an error similar to the following
Your target project [ProjectName] doesn't match your migrations assembly [ClasslibraryProjectName].
Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder.
E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("ProjectName")).
By default, the migrations assembly is the assembly containing the DbContext.
As the error message says, my target project should be the project that contains the migrations assembly, and the migration assembly is the assembly that contains the DbContext. If you are using visual studio for the development, you just need to change the default project to the class library project that contains the DbContext as shown below and rerun the migration command.
If you are using .NET Core CLI, the default project can be mentioned in the migration command as given below.
dotnet ef migrations add NewMigration --project WebApplication.DataAccess
Here, WebApplication.DataAccess is the class library project where I have the DbContext class.