Skip to content

Improve user experience for running migrations after deployment #6313

Closed as not planned
Closed as not planned

Description

@natemcmaster

Problem
Running migrations on deployment typically means you only have compiled output, not the project system. In theory, ef.exe/ef.dll should work well in this scenario, but figuring out all the arguments requires deep knowledge of how these tools work and is opaque to most users. Furthermore, ef.exe does not end up in compiled output, which requires users to do some NuGet cache spelunking to get the file.

Possible solutions

  • generate response files at design-time that ef.exe can parse on deployment
  • generate bash/cmd files that contain all the arguments for running an ef.exe command on compiled output
  • add msbuild targets to optionally put ef.exe/ef.dll in build output on publish

Activity

  1. added this to the Backlog milestone on Aug 12, 2016
  2. divega commented on Aug 12, 2016

    @divega
    Contributor

    cc @rowanmiller we move this to backlog for now but we can discuss pulling it in 1.1.0 or whether we should have better documentation on how to do it manually.

  3. Allann commented on Dec 5, 2016

    @Allann

    Any progress on this? I am keen to use this in our application as we are ready to migrate to new environments. I notice that ef.exe is now part of preview 3 and 4 and whilst the --help for the console app is somewhat helpful, a more detailed explanation of the options and commands would be helpful.

  4. changed the title [-]Improve user experience for running migrations on deployment[/-] [+]Improve user experience for running migrations after deployment[/+] on Dec 7, 2016
  5. bricelam commented on Jan 10, 2017

    @bricelam
    Contributor

    I've helped this scenario a little bit by logging our call to dotnet exec ef.dll in the PMC and CLI tools when -v (verbose) is specified. This is the same command you'd need to run on the server.

    dotnet exec --depsfile C:\Projects\ConsoleApp1\bin\Debug\netcoreapp1.0\ConsoleApp1.deps.json --runtimeconfig C:\Projects\ConsoleApp1\bin\Debug\netcoreapp1.0\ConsoleApp1.runtimeconfig.json C:\Users\bricelam.nuget\packages\microsoft.entityframeworkcore.tools.dotnet\1.0.0-msbuild3-final\tools\netcoreapp1.0\ef.dll database update --assembly C:\Projects\ConsoleApp1\bin\Debug\netcoreapp1.0\ConsoleApp1.dll

    It's a bit less dramatic on .NET Framework:

    C:\Users\bricelam.nuget\packages\microsoft.entityframeworkcore.tools.dotnet\1.0.0-msbuild3-final\tools\net451\ef.exe database update --assembly C:\Projects\ConsoleApp1\bin\Debug\net451\ConsoleApp1.exe

  6. benday commented on Mar 16, 2017

    @benday

    @bricelam -- Any updates on how to get this to work with the current version of EFCore? As a little background, I'm trying to do an assembly-based migration (not code-based) from TFS Release Management.

    Thanks,
    -Ben

  7. bricelam commented on Mar 17, 2017

    @bricelam
    Contributor

    Look at the output of dotnet ef database update --vervbose to see how it calls ef.exe (or ef.dll)

  8. benday commented on Mar 17, 2017

    @benday

    Thanks for the tip, @bricelam. To make it easier to call from an automated build or TFS Release Management, I turned the calls into a batch script. https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/

  9. pdesterlich commented on Mar 27, 2017

    @pdesterlich

    what about an app published on linux, where ef.dll is nowhere to be found?

  10. benday commented on Mar 29, 2017

    @benday

    Hi @pdesterlich --

    It works almost exactly the same but the paths are slightly different. I've just updated my blog post (https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/) to include a bash shell script for doing the deployment plus a sample of how to call it.

    Here's a direct link to the bash script: https://www.benday.com/wp-content/uploads/2017/03/deploy-ef-migrations.sh_.txt

  11. pdesterlich commented on Mar 29, 2017

    @pdesterlich

    thank you @benday for the reply, but it seems to me i'm missing something.
    what if i don't have a .nuget directory in my $HOME folder?

    maybe a bit of information about my test setup can help you to help me

    i have an asp.net core project, developed both on windows and linux; now i'm trying to deploy on a linux server; for my test i'm using a local virtual machine with ubuntu server 16.04 (i'm following more or less a tutorial found here: https://www.junian.net/2017/01/running-your-first-aspnet-core-web-app-on-ubuntu-16-04.html )
    I installed dotnet core with .deb package (instructions here: https://www.microsoft.com/net/core#linuxubuntu), then i copied my published app (dotnet publish -c Release) in /var/www/app-folder/

    When i run my app (with dotnet app-name.dll, or with service as in tutorial above) for some reason the first migration is automatically run, but any subsequent migration is ignored (the same happen in my dev machine if i try to run on a non existent database).

    I have no .nuget dir anywhere on the server, and i have no ef.dll file also.

    I could easily generate a migration script and manually apply it to the database, but i'd like to use migration on the deploy machine.

    What am i missing?

  12. benday commented on Mar 29, 2017

    @benday

    Hmm. If you can build your dotnet core project on that Ubuntu machine ("dotnet build"), then you definitely have a .nuget folder somewhere. I know that sometimes I get confused when I need to find something in a hidden folder in Linux -- any chance you aren't seeing your $HOME/.nuget directory because that folder is a hidden folder?

    What happens if you run the following lines?:
    cd $HOME
    ls -la

    Do you see a .nuget folder now?

    What about if you run "cd $HOME/.nuget"?

  13. pdesterlich commented on Mar 29, 2017

    @pdesterlich

    Well my ubuntu dev machine is a different machine from my ubuntu server.

    I already tried "ls -la" on home dir in ubuntu server but as said there isn't a .nuget dir.

    Keep in mind that everything i'm doing is on an ubuntu server wich is only a deploy server, no development is done on that server

  14. 7 remaining items

  15. Nogbit commented on Sep 27, 2017

    @Nogbit

    I'm building and deploying on and to Linux. I have to manually copy that ef.dll from my nuget dir to my /bin/Release as part of a separate deploy bash script. After the deploy runs it then runs the script I posted above. Works great, even with zero nuget folders on the server. Thanks for your help on this, it was your blog post I found when googling.

  16. benday commented on Sep 27, 2017

    @benday

    @Nogbit --

    Managing the location of that ef.dll is about 75% of the problem, huh? :)

    FYI, my TFS build task is cross-plat and works on Linux and on Windows build agents.

  17. Diaskhan commented on Jan 23, 2018

    @Diaskhan

    Hie guys!

    Is there some progress creating tool that could do migration after deploying assembly ???

  18. bricelam commented on Jan 23, 2018

    @bricelam
    Contributor

    The tool is available. Getting it on the server and invoking it are the hard parts (see comments above).

  19. Diaskhan commented on Jan 23, 2018

    @Diaskhan

    Maybe some One Provides A tutorial? I Have searched this solution about week !

  20. ajcvickers commented on Apr 24, 2018

    @ajcvickers
    Contributor
  21. removed this from the Backlog milestone on Apr 24, 2018
  22. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions