我的EF迁移如何与AppSettings.json一起使用。
目前,我在主项目中有一个appSettings.json文件,每当我需要其中定义的某些配置时,在所有项目中都使用它,但是对于我的持久性项目,我有另一个AppSettings.json文件,仅包含DB字符串,但我需要只有当我运行EF迁移,DB更新时,...否则它不起作用。
如果删除第二个文件,则项目有效,但是如果我尝试运行EF DB更新,则会获得此错误:
未找到配置文件'appsettings.json' 选修的。预期的物理路径是 'Project \ Persistence \ bin \ debug \ net6.0 \ appsettings.json'。
在主要项目中只有一个appsettings.json时,如何实现运行迁移?
Currently I have one appsettings.json file in the main project and use it in all projects whenever I need some of the configurations defined in it, but for my Persistence project I have another appsettings.json file that contain only db string, but I need it only when I ran EF migrations, db updates,... because otherwise it doesn't work.
If I remove that second file, project works, but if I try to run EF db update I get this error:
The configuration file 'appsettings.json' was not found and is not
optional. The expected physical path was
'Project\Persistence\bin\Debug\net6.0\appsettings.json'.
How can I achieve running migrations while having only one appsettings.json in the main project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当我试图将持久性层封装到一个单独的项目中时,我都会有类似的问题,因为它已被许多其他项目使用。就我所知,没有舒适的方法可以实现这一目标。即使这不是理想的,我也坚持使用单独的配置文件。
但是,基于选项的反解决方法是反思这一事实,将持久性层封装到单独的项目中可能没有用,因为它引入了类似框架的依赖性问题。它仅提供有意义的优势,如果一个以上的项目取决于它,因为这样的方式在几个项目之间共享持久性层代码。
I had a similar issue whenever i tried to encapsulate my persistence layer into a separate project, because it was used by many other projects. There is no comfortable way of achieving this as far i know. I stuck with having separate configuration files even though this wasn't ideal.
However, an option based anti-solution is to reflect onto the fact, that encapsulating the persistence layer into a separate project might not be useful, as it introduces framework dependent issues like this. It only provides a meaningful advantage, if more than one project depend on it, because that way the persistence layer code is shared between several projects.