无法在使用 Visual Studio for mac 的 .net core 2.1 项目中使用 add-Migration

问题描述

我正在使用 Visual Studio for Mac 并拥有 .NET Core 2.1 项目。使用“Add-Migration”等任何迁移命令时出现问题,即发生以下错误

**Add-Migration : The term ‘Add-Migration’ is not recognized as the name of a cmdlet,function,script file,or operable program.
Check the spelling of the name,or if a path was included,verify that the path is correct and try again.
At line:1 char:1
 + Add-Migration dbupdates -Context applicationdbcontext
 + ~~~~~~~~~~~~~
 + CategoryInfo         : ObjectNotFound: (Add-Migration:String) [],CommandNotFoundException
 + FullyQualifiedErrorId : CommandNotFoundException**

任何线索可能是什么原因?

解决方法

此错误表示缺少一个包。

从 nuget 安装包 Microsoft.EntityFrameworkCore.Tools。然后重新打开视觉工作室。

,

您可能缺少 nuget 包,如果情况并非如此,还要仔细检查 Visual Studio 中的 powershell 接口是否指向正确的项目(您希望 DbContext 对象存在并被定义)

enter image description here