Entity Framework 6 .net Framework Migrations / Package Management Console - How Do You Run These In An Azure Pipeline?

1.3k Views Asked by At

I am setting up an Azure Release Pipeline and I need to execute any pending DB Migrations as part of the release.

I have been scouring the internet for over an hour and everything I can find is about dotnet Core, while the database is EF6 on .Net Framework, not dotnet Core (I've done this several times before for Core).

The problem, as I see it, is that EF6 works using Visual Studio's built in Package Manager Console - This just doesn't exist in an Azure Pipeline; It's a Visual Studio weirdness.

There seems to be several ways I can skin this cat, in my head, but I can't figure out how to start with either of them within the context of the pipeline...

OPTION 1: Run the Migrations on the Pipeline - but... how?

OPTION 2: SQL Scripts - Requires running the Package Manager to generate them so they can be run (if I could do that on the pipeline then I'd just run it anyway so these would have to be created locally and committed with the code which is somewhat backward as a solution IMO)

OPTION 3: Write a console app - Do I really have to do this??

2

There are 2 best solutions below

0
Keith Jackson On BEST ANSWER

The answer here is to use the ef6.exe command line tool and make sure it gets shipped with your build.

This could be useful to anyone here until Microsoft update the non-existent docs: http://github.com/dotnet/EntityFramework.Docs/issues/1740 - This contains a table with a kind of translation matrix between the two.

3
Krzysztof Madej On

You can try Entity Framework Migration Extensions.

This task allows a Build / Release to provide database connection parameters and execute an Entity Framework 6 migration against the database.

  1. Build your project to an output folder and include the migrate.exe executable that comes with Entity Framework 6.
  2. Create an automated build that packages up your files and makes them accessible during a Release.
  3. Create a Release definition for the relevant Build
  4. Add an EF6 Migration task. Once that task is added to an environment within the release, you'll need to enter the appropriate parameters to configure it. All file path parameters should be within the file system for the build, none of them are for TFS source control paths.

You can also check this article.