在我的解决方案中,我有一个包含多个Entity Framework 6.1.3迁移配置类的Data项目。我的目标是从TeamCity运行实体框架迁移步骤 - 针对现有数据库中的一个迁移步骤(或者,从命令行简化)。
我正在使用的迁移配置类如下:
namespace MyProject.Data
{
public partial class MyCustomMigrationConfiguration :
DbMigrationsConfiguration<MyCustomContext>
{
public MyCustomMigrationConfiguration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = true;
MigrationsDirectory = @"Migrations\MyCustomContext\MigrationSteps";
}
}
}
我可以从Visual Studio中的程序包管理器控制台成功运行以下命令:
更新 - 数据库-Verbose -StartUpProject Web -ConnectionString&#39; -my 连接字符串在这里 - &#39; -ConfigurationTypeName MyCustomMigrationConfiguration -ConnectionProviderName &#39; System.Data.SqlClient的&#39;
我想从命令行做同样的事情,所以我运行它:
migrate.exe MyProject.Data.dll&#34; MyCustomMigrationConfiguration&#34; /startUpConfigurationFile=MyProject.Web.dll.config / connectionString =&#34; -my连接字符串在这里 - ;&#34; /connectionProviderName="System.Data.SqlClient" /冗长
但是,我收到以下错误:
错误:迁移配置类型 在程序集中找不到MyCustomMigrationConfiguration “MyProject.Data&#39;
有关如何解决此问题的任何建议,请?
答案 0 :(得分:1)
您可以指定运行代码所需的所有依赖项(程序集)所在的目录。您可以使用/startUpDirectory
选项as explained here:
指定工作目录
Migrate.exe MyApp.exe /startupConfigurationFile=”MyApp.exe.config” /startupDirectory=”c:\MyApp”
如果程序集具有依赖关系或相对于工作目录读取文件,则需要设置startupDirectory。
答案 1 :(得分:0)
找到解决方案(我最终从http://entityframework.codeplex.com/下载了Entity Framework源代码并调试了迁移控制台应用程序)。
显然,MyProject.Data.dll的所有依赖项都需要与它和migrate.exe复制到同一个文件夹中,否则Entity Framework migrate.exe工具将抛出上面的误导性错误消息。
在这种情况下,实体框架确实可以使用更好的错误处理和更清晰的错误消息。
作为对Entity Framework开发人员的引用:TypeFinder.cs中的以下代码返回null类型,因为MyProject.Data.dll的依赖关系未复制到migrate.exe文件夹中:
type = _assembly.GetType(typeName, false);