Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Migrate.exe to work

I have been struggling on executing EF Migrate.exe to work.

My Solution has couple of projects. The migrations and the entities live in the project Data. The controllers and views live in Web.

I tried using the migrate.exe - however I am struggling getting the first argument (assembly) to be accepted. Documentations says:

Assembly: Specifies the name of the assembly that contains the migrations configuration type.

I have tried:

migrate.exe "MySolution\DataProject\bin\Debug\Data.dll"

ERROR: Could not load file or assembly 'D:\\MySolution\\Data\\bin\\Debug\\Data' or one of its dep
endencies. The given assembly name or codebase was invalid. (Exception from HRES
ULT: 0x80131047)

Any idea what is going wrong?

like image 993
Karan Avatar asked Aug 03 '12 10:08

Karan


People also ask

What is migrate EXE?

Migrate.exe (FluentMigrator. This is a console tool that works also with the . NET Framework outside of the . NET Core ecosystem.

Where is ef6 EXE located?

The ef6.exe command line tool is found in the tools/ subfolder of the EntityFramework NuGet package.


2 Answers

After reading this, this, and this

I have (I think) what you need :

  1. If you use migrate.exe against a .NET 4 assembly you NEED to rename the Redirect.config available in packages\EntityFramework.5.0.0\tools to migrate.exe.config and copy this to the SAME directory as migrate.exe. For running migrate.exe against a .NET 4.5 assembly you DO NOT NEED this copy, the migrate.exe.config must not exist.
  2. The correct version of entity framework DLL must be in the SAME directory as migrate.exe. Correct version is packages\EntityFramework.5.0.0\lib\net40\ for running migrate.exe against a .NET 4 assembly. Correct version is packages\EntityFramework.5.0.0\lib\net45\ for running migrate.exe against a .NET 4.5 assembly
  3. If you specify /StartUpDirectory= do not specify the path for /assembly example : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\.
  4. If you don't specify a startup directory, then you need to specify the full path in the /assembly example : C:\Tools\migrate.exe C:\Project\bin\some.dll - In this scenario migrate.exe will not be able to load the some.dll's dependencies, unless you put all some.dll's dependencies and put it in the SAME directory as migrate.exe.
  5. If you put the migrate.exe in the same path as your some.dll, then migrate.exe will be able to use the same EntityFramework.dll which your app uses, and can load all dependencies, and can load the some.dll without any path like C:\Tools\migrate.exe some.dll
  6. If you put the migrate.exe in a separate tools folder like Im doing it needs the correct version of the EntityFramework.dll in the SAME directory as migrate.exe, it will need the /StartUpDirectory=<the path where you target dll is present> clause, and you should specify the name of the assembly without the path like : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
  7. Heres the powershell commmand I use :
$SolutionPath = (Resolve-Path '..').Path
$ToolsPath = "$SolutionPath\Build\Lib\"

task db  { 
  $migrator = $ToolsPath + 'Migrations\migrate.exe'  
  $migrateCommand = "$migrator zasz_me.dll /StartUpDirectory=$SolutionPath\zasz.me\bin\ /connectionStringName:FullContext /startUpConfigurationFile:$SolutionPath\zasz.me\Web.config /verbose"
  Write-Host $migrateCommand
  Invoke-Expression $migrateCommand
}
like image 93
Zasz Avatar answered Oct 15 '22 05:10

Zasz


I answered a similar question here on how to override connectionstring through parameters to migrate.exe. I have yet to get it working without specifying a web/app.config file.

https://stackoverflow.com/a/14138797/134761

like image 31
angularsen Avatar answered Oct 15 '22 03:10

angularsen