未找到 EF Core 工具 System.Configuration.ConfigurationManager 程序集 [英] EF Core tools System.Configuration.ConfigurationManager assembly not found

查看:38
本文介绍了未找到 EF Core 工具 System.Configuration.ConfigurationManager 程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用 EF Core 2 进行迁移的新应用程序.应用程序本身是 .net Framework,但模型位于单独的 .net core 2.0 程序集中.一切正常我已经定义了一个设计时上下文工厂:

I am creating a new application that is using EF Core 2 with migrations. The application itself is .net Framework but the model is in a separate .net core 2.0 assembly. Everything is working fine I have defined a designtime context factory:

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

我可以生成迁移并将它们应用/还原到数据库.现在,如果我用对配置文件的调用替换硬编码的连接字符串

And I can generate migrations and apply/revert them to the DB. Now if I replace hardcoded connection string with a call to config file

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

我在调用 EF Core 工具时出错:

I have an error when calling EF Core tools:

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核心工具不是在寻找模型程序集的依赖...

However the nuget is there and I can access ConfigurationManager in ContextFactory (not the designtime one) with no problem when launching the application itself. Looks like EF core tools are not looking for the dependencies of the model assembly...

有什么我遗漏的吗?也许无法在 DesignTime 上下文工厂中使用 ConfigurationManager?

Is there something I am missing? Maybe it is not possible to use ConfigurationManager in DesignTime context factory?

推荐答案

最后问题出在应用项目上.我必须将 System.Configuration.ConfigurationManager 的 nuget 包添加到 .Net Framework 应用程序,以便 PackatManager 可以找到它.有点奇怪,它在运行时有效,但在设计模式"下​​无效.

Finally the problem was in the application project. I had to add the nuget package for System.Configuration.ConfigurationManager to the .Net Framework app so the PackatManager can find it. A bit weired that it works at runtime but not in "design mode".

这篇关于未找到 EF Core 工具 System.Configuration.ConfigurationManager 程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆