我正在创建一个使用efcore2进行迁移的新应用程序。
应用程序本身是.NETFramework,但模型位于单独的.NETCore2.0程序集中。一切正常我定义了一个designtime上下文工厂:
public class MyDesignTimeContextFactory : IDesignTimeDbContextFactory<MyContext>
{
public MyContext CreateDbContext(string[] args)
{
return new MyContext("Server=localhost\\SQLEXPRESS;Database=DBName;User ID=Test;Password=0000;");
}
}
我可以生成迁移并将它们应用/恢复到数据库。
现在,如果我用对配置文件的调用替换硬编码的连接字符串
return new MyContext(System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString");
Add-Migration -Project MyProject.Model -Name Initialization
System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.1.0 ....,
但是nuget在那里,我可以在ContextFactory(而不是designtime)中访问ConfigurationManager,在启动应用程序本身时没有问题。看起来EF核心工具没有查找模型程序集的依赖项。。。
有什么我不知道的吗?可能无法在DesignTime上下文工厂中使用ConfigurationManager?