You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve user experience for running migrations after deployment #6313
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
Reacted by mafshin, Himadri Nath, Halid Cisse, Jared Prather, Allan Nielsen, nicolasr75, Gergely Kalapos, Thien Nguyen Le Quynh, Marcellus Miles, Soheil Alizadeh and 3 more
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.
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.
changed the title [-]Improve user experience for running migrations on deployment[/-][+]Improve user experience for running migrations after deployment[/+]on Dec 7, 2016
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.
@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.
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.
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
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.
Activity
divega commentedon Aug 12, 2016
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.
Allann commentedon Dec 5, 2016
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.
[-]Improve user experience for running migrations on deployment[/-][+]Improve user experience for running migrations after deployment[/+]bricelam commentedon Jan 10, 2017
I've helped this scenario a little bit by logging our call to
dotnet exec ef.dllin the PMC and CLI tools when-v(verbose) is specified. This is the same command you'd need to run on the server.It's a bit less dramatic on .NET Framework:
benday commentedon Mar 16, 2017
@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
bricelam commentedon Mar 17, 2017
Look at the output of
dotnet ef database update --vervboseto see how it callsef.exe(oref.dll)benday commentedon Mar 17, 2017
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/
pdesterlich commentedon Mar 27, 2017
what about an app published on linux, where ef.dll is nowhere to be found?
benday commentedon Mar 29, 2017
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
pdesterlich commentedon Mar 29, 2017
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?
benday commentedon Mar 29, 2017
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"?
pdesterlich commentedon Mar 29, 2017
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
7 remaining items
Nogbit commentedon Sep 27, 2017
I'm building and deploying on and to Linux. I have to manually copy that
ef.dllfrom my nuget dir to my/bin/Releaseas 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.benday commentedon Sep 27, 2017
@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.
Diaskhan commentedon Jan 23, 2018
Hie guys!
Is there some progress creating tool that could do migration after deploying assembly ???
bricelam commentedon Jan 23, 2018
The tool is available. Getting it on the server and invoking it are the hard parts (see comments above).
Diaskhan commentedon Jan 23, 2018
Maybe some One Provides A tutorial? I Have searched this solution about week !
bricelam commentedon Jan 23, 2018
@benday has some good guidance and automation tips: https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/
ajcvickers commentedon Apr 24, 2018
Closing in favor of dotnet/EntityFramework.Docs#691