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

oyxsuwqo  于 2022-12-07  发布在  Mac
关注(0)|答案(5)|浏览(148)

我有Visual Studio for Mac,我正在尝试使用以下教程学习Xamarin with Azure:https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/server/
在某些情况下,我必须启用EF迁移。教程内容如下:转到“查看”-〉“其他窗口”-〉“程序包管理器控制台”。
不幸的是,Visual Studio for Mac中没有软件包管理器控制台...那么您如何在Mac上处理enable-migrationsadd-migrationupdate-database之类的问题呢?

ukqbszuj

ukqbszuj1#

This is currently supported on Mac.

First you need to install dotnet-ef
dotnet tool install --global dotnet-ef
To install a specific version of the tool, use the following command:
dotnet tool install --global dotnet-ef --version 3.1.4
Add the "dotnet-ef" tools directory on the PATH environment variable.
export PATH="$PATH:/Users/'your user folder'/.dotnet/tools"
Open a command line, go to the project folder, and run
dotnet restore
If everything is fine, you should be able to run
dotnet ef
After that you can run commands like:
dotnet ef migrations add initial
dotnet ef database update

PS: Your solution should not be executing when the dotnet ef command line is trying to run!!!

For People who are not convinced, here a demo of succeed!!!

doinxwow

doinxwow2#

要在Mac上运行EF,只需按照以下步骤操作。
打开命令行,转到项目文件夹,然后运行
点网还原
如果一切正常,你应该能跑
点网络EF
之后,您可以运行如下命令:
dotnet ef迁移添加初始
dotnet ef数据库更新

4c8rllxm

4c8rllxm3#

Visual Studio for Mac的开箱即用功能目前不支持此功能。
有一个NuGet扩展加载项可将PowerShell控制台添加到Visual Studio for Mac。此加载项可从扩展管理器访问,并提供NuGet程序包管理器控制台窗口(可从“视图”-“其他窗口”菜单访问)。此加载项允许您运行可在Windows上的Visual Studio中运行的EF PowerShell命令。
如果您使用的是Entity Framework 7(或者他们称之为Entity Framework Core),那么您应该能够将这些命令与.NET Core command line一起使用。

dotnet ef migrations ...

如果您使用的是Entity Framework 6,则需要寻找其他方法来调用迁移,而不是使用PowerShell。Entity Framework 6具有特定于Visual Studio的PowerShell命令。它们已移植到SharpDevelop,但需要重写它们以与该IDE一起使用。

bmp9r5qi

bmp9r5qi4#

如果您使用的是.NET核心(特别是EF核心),则可以在Visual Studio for Mac中安装NuGet PowerShell核心控制台。
只需按照以下网址中的说明进行操作:
https://lastexitcode.com/blog/2019/05/05/NuGetPowerShellCoreConsoleVisualStudioForMac8-0/

67up9zun

67up9zun5#

Mac用户
如果您有N层体系结构和多个项目,请确保在正确的路径(可能在启动项目路径下)上运行命令
我遇到问题是因为走错了路
dotnet ef数据库更新
当然你必须先安装ef
dotnet工具安装--全域dotnet-ef--版本{VERSION_NUMBER}
然后导出路径
导出路径="$PATH:/用户/文件系统/. dotnet/工具"
如果您的设置指向本地数据库,请不要忘记在本地安装数据库。首先安装并尝试连接它,然后应用dotnet ef数据库更新命令。

相关问题