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

查看:233
本文介绍了如何确保将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.

如果右键单击文件并选择属性,则会出现此对话框.将构建操作更改为嵌入式资源,文件将被复制到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天全站免登陆