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

查看:306
本文介绍了找不到EF核心工具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核心工具System.Configuration.ConfigurationManager程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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