EF Core tools System.Configuration.ConfigurationManager assembly not found

天大地大妈咪最大 提交于 2019-12-11 15:58:09

问题


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");

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 ....,

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...

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


回答1:


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".



来源:https://stackoverflow.com/questions/53169392/ef-core-tools-system-configuration-configurationmanager-assembly-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!