web/app.config ファイルを指定せずに実際に機能するソリューションをまだ見つけていません。下記参照。
ただし、web/app.config を提供し、接続文字列をコマンドライン パラメーターとしてオーバーライドすることを受け入れることができる場合、以下は Entity Framework 5.0 nuget および .NET 4.5 で機能します。.NET 4.0 でも文書化された回避策で動作するはずです。
フォルダ構造の例:
trunk\MySolution.sln
trunk\run_migration.bat
trunk\MyMvc4App\MyMvc4App.csproj
trunk\MyMvc4App\web.config
trunk\MyMvc4App\bin\MyMvc4App.dll
trunk\MyMvc4App\bin\EntityFramework.dll
trunk\packages\EntityFramework.5.0.0\tools\migrate.exe
run_migration.bat:
SET AssemblyName=MyMvc4App
SET StartUpDirectory=MyMvc4App\bin\
SET ConnectionString=Server=tcp:XXXX.database.windows.net,1433;Database=XXXX;User ID=XXXX;Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True
SET ConnectionStringProvider=System.Data.SqlClient
SET ConfigFilePath=%CD%\MyMvc4App\web.config
SET MigrateExe=packages\EntityFramework.5.0.0\tools\migrate.exe
%MigrateExe% %AssemblyName%.dll /startUpDirectory:%StartUpDirectory% /startUpConfigurationFile:"%ConfigFilePath%" /connectionProviderName:"%ConnectionStringProvider%" /connectionString:"%ConnectionString%" /verbose
pause
ソリューションの終了。
構成ファイルの省略:
構成ファイルを省略しようとすると、何を試しても常に次の例外が発生しました。私は EF 4.3 を試していないので、4.3 と 5.0 の間で動作が変わったのではないかと思います。
System.Data.Entity.Migrations.Design.ToolingException: Exception has been thrown by the target of an invocation.
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.Console.Program.Run()
at System.Data.Entity.Migrations.Console.Program.Main(String[] args)
ERROR: Exception has been thrown by the target of an invocation.