如何在Visual Studio for Mac中启用迁移

fra*_*swa 8 entity-framework xamarin visual-studio-mac

我有Visual Studio for Mac,我正在尝试使用以下教程学习Xamarin:https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/server/

在某些时候,我必须启用EF迁移.教程说:转到视图 - >其他Windows - >程序包管理器控制台.

不幸的是,Visual Studio for Mac中没有软件包管理器控制台...所以你如何处理这样的东西enable-migrations,add-migration或者update-database在Mac上?

小智 23

要在 Mac 上运行 EF,只需按照以下步骤操作。

打开命令行,转到项目文件夹,然后运行

dotnet 还原

如果一切正常,您应该可以运行

dotnet ef

之后,您可以运行以下命令:

dotnet ef 迁移添加初始

dotnet ef 数据库更新

  • 我必须像这样运行安装 -- dotnet tool install -g dotnet-ef。有关于此的更多详细信息,请访问:https://docs.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli (5认同)
  • 仅供参考...如果 dotnet EF 没有,您可能需要安装 dotnet 工具,因为它已在 .net core 3.0 中删除 (2认同)

Mat*_*ard 14

Visual Studio for Mac目前不支持此功能.

有一个NuGet扩展插件,可以为Visual Studio for Mac添加PowerShell控制台,但Entity Framework PowerShell命令不太可能工作,因为它们通常是特定于Visual Studio的.此外,PowerShell支持是有限的,因为它使用Pash,PowerShell的开源克隆,尚未完全实现.

如果您正在使用Entity Framework 7(或他们称之为Entity Framework Core),那么您应该能够使用.NET Core命令行中的命令.

dotnet ef migrations ...
Run Code Online (Sandbox Code Playgroud)

如果您使用的是Entity Framework 6,那么您需要找到另一种方法来调用迁移而不是使用PowerShell.实体框架6具有特定于Visual Studio的PowerShell命令.他们被移植到SharpDevelop,但涉及重写它们以使用该IDE.


G C*_*ovs 11

Mac 目前支持此功能。

首先你需要安装 dotnet-ef

dotnet tool install --global dotnet-ef

要安装该工具的特定版本,请使用以下命令:

dotnet tool install --global dotnet-ef --version 3.1.4

在 PATH 环境变量中添加“dotnet-ef”工具目录。

export PATH="$PATH:/Users/'your user folder'/.dotnet/tools"

打开命令行,转到项目文件夹,然后运行

dotnet restore

如果一切正常,您应该可以运行

dotnet ef

之后,您可以运行以下命令:

dotnet ef migrations add initial

dotnet ef database update

PS:当 dotnet ef 命令行尝试运行时,您的解决方案不应执行!!!

对于不相信的人,这里是成功的演示!!! 对于不相信的人,这里是成功的演示!!!


Chi*_*obe 6

如果您使用 .NET Core(特别是 EF Core),则可以在 Visual Studio for Mac 中安装 NuGet PowerShell Core 控制台。

只需按照以下网址中描述的说明进行操作即可:

https://lastexitcode.com/blog/2019/05/05/NuGetPowerShellCoreConsoleVisualStudioForMac8-0/