How to enable migrations in Visual Studio for Mac
Solution 1
This is not currently supported with Visual Studio for Mac.
There is a NuGet extensions addin that adds a PowerShell console to Visual Studio for Mac however the Entity Framework PowerShell commands are unlikely to work since they are typically Visual Studio specific. Also the PowerShell support is limited since it uses Pash, an open source clone of PowerShell, which is not fully implemented.
If you are using Entity Framework 7 (or what they are calling Entity Framework Core) then you should be able to use the commands with the .NET Core command line.
dotnet ef migrations ...
If you are using Entity Framework 6 then you would need to find another way to call the migrations instead of using PowerShell. Entity Framework 6 has PowerShell commands that are specific to Visual Studio. They were ported to SharpDevelop but involved re-writing them to work with that IDE.
Solution 2
To run EF on Mac just follow the following.
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
Solution 3
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!!!
Solution 4
If you are using .NET Core (specifically EF Core), you can install the NuGet PowerShell Core Console in Visual Studio for Mac'.
Just follow the instructions described at:
https://lastexitcode.com/blog/2019/05/05/NuGetPowerShellCoreConsoleVisualStudioForMac8-0/
Related videos on Youtube
franswa
Updated on March 12, 2022Comments
-
franswa over 2 years
I have Visual Studio for Mac and I'm trying to learn Xamarin with Azure using the following tutorial: https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/server/
At some point, I have to enable EF migrations. The tutorial says: Go to View -> Other Windows -> Package Manager Console.
Unfortunately there is no Package Manager Console in Visual Studio for Mac... so how do you handle things like
enable-migrations
,add-migration
orupdate-database
on the Mac?-
SushiHangover almost 7 yearsThe Visual Studio
Package Manager Host
is not currently supportedmacOS
using the PowerShell beta and thus trying to install/initEntityFramework.psm1
will fail as running powershell will result in aConsoleHost
and thus trying to runImport-Module
on the EntityFramework PS module will fail. The migration cmds are fairly thin wrappers over the entity framework apis and you can convert them to a C# cmd-line app fairly easily, but it is fair easier to spin up a Windows VM on the Mac... sucks, but those are the two options available today : stackoverflow.com/a/20382226/4984832 -
Matt Ward almost 7 yearsIt is more than just supporting the Package Manager Host. There is a separate NuGet extensions addin that adds a PowerShell console. The problem is that, at least with EF 6, the PowerShell commands are Visual Studio specific. When I integrated support for the EF 6 in SharpDevelop all the PowerShell commands needed to be rewritten to work with the host IDE. EF 7 has provided cross platform commands that work on the command line using the dotnet cli. However PowerShell integration is a another problem.
-
G Clovs over 3 yearsHello this is currently supported on Mac please change the answer. Regards ;)
-
-
user1703401 over 6 years
-
JordanGW over 4 yearsFYI... If dotnet EF doesn't you may need to install dotnet tools as it was removed in .net core 3.0
-
Taylor Maxwell about 4 yearsI had to run the install like this -- dotnet tool install -g dotnet-ef. There is more detail on this at: docs.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli
-
G Clovs over 3 yearsIt should I am on Mac and this is working very well. You have to use it at the racine of your solution
-
G Clovs over 3 yearsHaha you troll me bro, the command line exist. You should found a way to make it work. I am using it every day
-
G Clovs over 3 yearsYou have to run it when your project is not running.
-
somedirection about 2 yearsI needed to update to latest dotnet tool update --global dotnet-ef