I have been going round in circles trying to get EF to run my migrations via powershell, but getting no where. I can run them through visual studio, using the package manager console, but when I run it using a powershell script I get the error:
migrate.exe : At line:1 char:1 + & "C:\Development\Ef\Tools\migrate.exe" "TestApp.Data.dll" /connect ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:String) , RemoteException + FullyQualifiedErrorId : NativeCommandError Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'EntityFramework, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. at System.Data.Entity.Migrations.Console.Resources.EntityRes..ctor()
at System.Data.Entity.Migrations.Console.Resources.EntityRes.GetLoader() at System.Data.Entity.Migrations.Console.Resources.EntityRes.GetString(String name, Object args) at System.Data.Entity.Migrations.Console.Program.WriteError(String message) at System.Data.Entity.Migrations.Console.Program.Main(String args)
The modified script I'm running (generated by octopus) is:
& "C:\Development\Ef\Tools\migrate.exe" "TestApp.Data.dll" /connectionProviderName="System.Data.SqlClient" /startupConfigurationFile="C:\Development\FeatureBranch\TestApp\TestApp.Root\TestApp.WebApi\web.config" /startUpDirectory="C:\Development\FeatureBranch\TestApp\TestApp.Root\TestApp.WebApi\bin" /Verbose
I have google'd this a lot and I know this is a common issue, so I have done the following checks:
EF version install via nuget is 6.1.3. This is the same across all of the package.config files in the solution, i.e.:
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
I have checked all the web and app configs and they are all consistent:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
This looks a bit odd to me, though I would assume that nuget would set this correctly? Either way, changing these values makes no difference.
I have checked there are no older versions of the ef lying around. The migrate.exe I'm using is the version from my packages folder that nuget downloaded and it states that it's version is 6.1.3-40302. I am running .net 4.5 which matches the packages config.
Any advice will be appreciated and I will try, maybe I'm missing something obvious.
So, I managed to fix this if anyone else has the same issue. The script from Octopus wasn't great, so I wrote it from scratch. The key issue for me at least was that the script needs to copy the migrate.exe into the folder where the TestApp.Data.dll is located and to execute it from there.