Search code examples
entity-frameworkxamarinvisual-studio-mac

How to enable migrations in Visual Studio for Mac


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?


Solution

  • 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!!!