问题
Moved to ef 4.3 with
AutomaticMigrationsEnabled = true;
In web.config
have the following settings:
<appSettings configSource="appSettings.config" />
<connectionStrings configSource="connectionStrings.config" />
In Package Manager Console execute
update-database -verbose
and got the following error:
System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'connectionStrings.config'
The error is understandable: it tries to open connectionStrings.config
file from the working directory which is not the root project directory where connectionStrings.config
file exists.
If connectionStrings.config and appSettings.config content to be moved to the web.config all works like a charm.
Is it a bug a it can be solved somehow?
回答1:
When the migrations are run, it appears that binaries and the config file are copied to a temp directory. The files referenced as configSource
are not copied over. I've tried marking the configSource
files to be copied in the build, to no luck.
I reverted back to putting the connection string right into the app.config of the class library that contains my dbcontext and migrations. I have a separate class library for that, so my web.config of the main web project can still use configSource
.
回答2:
Seems like this error was fixed in 4.3.1.
Enabled support for configsource in configuration files when using Code First Migrations.
回答3:
Using EF 6.1 here.
If like me you were linking to a connectionStrings.config file located in another project than your Entity Framework migrations project (using Add as link), you'll probably need to move the file back to this EF project and link to the moved file from the other projects instead...
来源:https://stackoverflow.com/questions/9284289/entity-framework-4-3-update-database-when-configuration-files-are-separated