How to enable migrations in Visual Studio for Mac

Viewed 37283

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 or update-database on the Mac?

5 Answers

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

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!!! For People who are not convinced, here a demo of succeed!!!

Mac Users

If you have N-Layer Architecture and multiple projects, make sure you're running command on the right path (possibly under the startup project path)

I was having issues because of a wrong path

dotnet ef database update

Of course you have to install ef first

dotnet tool install --global dotnet-ef --version {VERSION_NUMBER}

then export path

export PATH="$PATH:/Users/firatkeler/.dotnet/tools"

And do not forget to install db locally if your settings are pointing to a local db. Install and try to connect it first, then apply dotnet ef database update command.

Related