I had this same scenario happen on our project that spans now ~20 years in history.
It has everything from Web Forms, to latest .Net Core technologies.
Depending on luck, I would sometimes get that PackageManagerConsole
was using EFCore
sometimes EF6
.
I was not happy that I had to use prefixes like above answer stated so I dug deeper.
If you run command Get-Module
in your PM> PackageManagerConsole
you should get list of active modules:
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 6.4.4 EntityFramework6 {Add-EFDefaultConnectionFactory, Add-EFProvider, Add-Migration, Enable-Migrations...}
Script 5.0.10 EntityFrameworkCore {Add-Migration, Drop-Database, Enable-Migrations, Get-DbContext...}
Script 2.0.0.0 NuGet {Add-BindingRedirect, Find-Package, Get-Package, Get-Project...}
Script 0.0 profile
Problem here is as you can see and probably even know that both EntityFramework Core and 6
are being used by solution.
You can remove one of the modules that are conflicting, using command:
PM> Remove-Module <module-name-from-list>
What I needed was to use only EFCore so I removed EF6 module like so:
PM> Remove-Module EntityFramework6
And then you can use commands without prefixes, e.g.:
PM> Add-Migration TestMigration
Relevant discussion I had with EF team: https://github.com/dotnet/efcore/issues/27051
EntityFrameworkCore\Add-Migration anything
?dotnet ef add-migration
if you get an error sayingdotnet-ef
isn't a command, then you're missing the tooling from your.CSPROJ
file.