What is the correct format for Running Entity Framework migrate.exe tool without a Web/App.config?

折月煮酒 提交于 2019-11-30 04:43:15

Ok, we figured it out. When running without the Web.config, the connectionProviderName parameter must also be passed in:

ProjectName\packages\EntityFramework.4.3.1\tools\migrate.exe MyAssembly
    /startupdirectory:ProjectName\bin\Debug 
    /connectionProviderName:"System.Data.SqlClient"
    /connectionString:"Data Source=awesomeserver;Initial Catalog=awesomedatabase;User Id=funkyuser;Password=crazypassword" 
    /verbose

I have confirmed that this works.

I have yet to find a solution that actually works without specifying the web/app.config file. See below.

However, if you can accept providing a web/app.config and overriding the connection string as command-line parameters, then the following works with Entity Framework 5.0 nuget and .NET 4.5. Should also work for .NET 4.0 with the documented workarounds.

Example folder structure:

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

End of solution.


Omitting the configuration file:

If trying to omit the configuration file, I always got the following exception no matter what I tried. I didn't try EF 4.3, so I suspect the behavior changed between 4.3 and 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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!