-->

EF核心工具System.Configuration.ConfigurationManager总成没

2019-10-29 22:57发布

我创建一个使用EF酷睿2与迁移的一个新的应用程序。 应用程序本身是.NET框架但该模型是在一个单独的.NET 2.0核心组件。 一切工作正常我已经定义了一个设计时上下文工厂:

public class MyDesignTimeContextFactory : IDesignTimeDbContextFactory<MyContext>
{
    public MyContext CreateDbContext(string[] args)
    {
        return new MyContext("Server=localhost\\SQLEXPRESS;Database=DBName;User ID=Test;Password=0000;");
    }
}

我可以生成迁移和应用/它们恢复到数据库。 现在,如果我硬编码替换连接字符串通过调用CONFIG文件

return new MyContext(System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString");

调用EF核心工具时,我有一个错误:

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访问ConfigurationManager中(而不是设计时的一个)。 看起来像EF核心工具是不是在找模型组件的依赖...

有什么我失踪? 也许这是不可能在设计时上下文工厂使用ConfigurationManager中?

Answer 1:

最后的问题是在应用程序项目。 我不得不为System.Configuration.ConfigurationManager添加NuGet包到.NET Framework应用程序,因此PackatManager可以找到它。 有点weired,它工作在运行而不是在“设计模式”。



文章来源: EF Core tools System.Configuration.ConfigurationManager assembly not found