How can I call Add-Migration without parameters

435 Views Asked by At

I have .net Core 3.1 solution with WebApi and Persistance projects. WebApi is the solution's startup project, Persistance is where DbContext is defined. After a lot of reading and trying stuff, I still cannot achieve the following:

  1. WebApi stays as the solution's startup project.
  2. Migrations folder with all the migrations classes is in the Persistance project.
  3. Migrations can be generated from VS Package Manager Console by typing Add-Migration <migration_name> without any additional parameters like -Project or -StartupProject.
  4. No need to change selection in the Package Manager Console Default project dropdown.
1

There are 1 best solutions below

0
On

I wanted to achieve the same result but on MAC OS. Because Visual Studio on Mac is not like Window's, We use CLI commands. In my case I had Migration Classes in another project and startup was Api project just like you so i added this to my terminal :

alias migrationfortest='dotnet ef migrations add $1 --project /Users/user/Projects/test-web/Test.Infrastructure'

and you can call this simply by typing migrationfortest "YOURMIGRATIONNAME"

NOTE : For CLI command tools you should add This