如何确保 appsettings.dev.json 被复制到输出文件夹? [英] How can I ensure that appsettings.dev.json gets copied to the output folder?

查看:30
本文介绍了如何确保 appsettings.dev.json 被复制到输出文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个配置文件,每个环境一个:

I have three configuration files, one for each environment:

  1. appsettings.json -> 生产
  2. appsettings.dev.json -> 开发
  3. appsettings.stg.json -> 暂存

如果我将 ASPNETCORE_ENVIRONMENT 设置为 dev,我会收到一个运行时异常,抱怨找不到 appsettings.dev.json.我尝试添加

If I set ASPNETCORE_ENVIRONMENT to dev, I get a runtime exception complaining about not being able to find appsettings.dev.json. I tried adding

"copyToOutput": [
  "appsettings.dev.json"
]

到 project.json 中的 buildOptions 部分,但它似乎没有任何效果.

to the buildOptions section in project.json but it doesn't seem to have any effect.

还有其他方法可以强制将 appsettings.dev.json 复制到输出目录吗?

Is there another way I can force appsettings.dev.json to be copied to the output directory?

推荐答案

就我而言,appsettings.json 没有被复制用于单元测试.

In my case, appsettings.json is not being copied for unit tests.

如果您右键单击该文件并选择属性,则会出现此对话框.将 Build Action 更改为 Embedded resource,该文件将被复制到 bin 文件夹以供单元测试选取.

If you right click the file and choose Properties, this dialog will come up. Change Build Action to Embedded resource and the file will be copied to the bin folder for the unit test to pick up.

这篇关于如何确保 appsettings.dev.json 被复制到输出文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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