我们的项目历时约20年,涵盖了从Web Forms到最新的.Net Core技术的一切。有时候会出现PackageManagerConsole使用EFCore,有时候会使用EF6,这种情况在运气好的时候发生。
我不喜欢像上面的答案那样使用前缀,所以我深入挖掘了一下。
如果您在PM> PackageManagerConsole中运行Get-Module命令,您应该可以获得活动模块的列表:
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
问题在于,正如您所看到并且可能已经知道的那样,解决方案中同时使用了EntityFramework Core和6
。
您可以使用以下命令之一删除其中一个发生冲突的模块:
PM> Remove-Module <module-name-from-list>
我需要的是仅使用EFCore,所以我移除了EF6模块。
PM> Remove-Module EntityFramework6
然后,您可以使用无前缀的命令,例如:
PM> Add-Migration TestMigration
我与EF团队进行了有关讨论:https://github.com/dotnet/efcore/issues/27051
EntityFrameworkCore\Add-Migration anything
是什么意思? - Ivan Stoev.CSPROJ
文件中的工具。你可以尝试使用dotnet ef add-migration
命令。 - Adam Vincent