Using NuGet Package Manager console outside Visual Studio to run Entity Framework Migrations

The original posted answer was right at the time, but now (as of 4.3) there is a migrate.exe so you don't need nuget or powershell:

packages\EntityFramework.4.3.1\tools\migrate.exe

See http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx


The link for migrate.exe info is out-dated. Since this post helped me here is the latest for other folks who stumble upon this:

http://msdn.microsoft.com/en-us/data/jj618307.aspx

Summary: The article gives you instructions on getting migrate.exe installed and using the command line arguments to perform your migration scenario with it. In addition, common issues are identified. Bottom line install EF with nuget and browse to the package's tools folder to find the exe.


Here's a PowerShell function which does the equivalent of update-database in the Package Manager console, from a normal PowerShell window, using EF x.x.x.

I'm using it from the command line as part of a 'full build' process on my dev machine;

function Update-Database($solutionDir, $projectBinDir, $assemblyName, $appConfigFile)
{
    $efMigrateExe = "$solutionDir\packages\EntityFramework.*\tools\migrate.exe"
    Write-Host "Updating Entity Framework Database"
    Write-Host "    Migrate.exe at $efMigrateExe"
    Write-Host "    EF project binary at $projectBinDir"
    Write-Host "    EF config at $appConfigFile"
    . "$efMigrateExe" "$assemblyName" /startupConfigurationFile="$appConfigFile" /startupDirectory="$projectBinDir"
}

The parameters are;

$solutionDir -- the directory where your solution lives; the parent of the packages folder. $projectBinDir -- the <something>\bin\debug directory containing the assembly with your DbContext. $assemblyName -- the name of the assembly file, like MyEfProject.dll appConfigFile -- the name of the app.config or web.config file which contains connection strings etc. Equivalent to using -StartupProjectName in the Package Manager console.