How can I ensure that appsettings.dev.json gets copied to the output folder?

社会主义新天地 提交于 2019-11-28 23:30:38

Including this in "project.json" works for me:

...
"publishOptions": {
  "include": [
    "wwwroot",
     ...
    "appsettings.json",
    "appsettings.Development.json",
    ...
  ]
},
...

Have you set the base path where appsettings.dev.json is placed?

var builder = new ConfigurationBuilder()
    .SetBasePath(env.ContentRootPath)
    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

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

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.

In solution explorer right click on your file that want to be copied to output (in your case appsettings.dev.json) and hit Properties, In Properties window pane set Copy To Output Directory option to Copy Always. By doing so, every time you build your project, your file will be copied into output directory (your project bin or release directory depending on your build profile)

Assumes you are using Visual Studio:

Typically for services in the past I have had other devs set up 'Build Events' that ensure that certain things in the project get built. Typically it would be in ASP.NET project properties for Visual Studio 2015 as an example: >'Build Events'(left pane)>Click 'Edit Post-build'. Write in command line instructions of how the project should build to output. EG:

mkdir "$(ProjectDir)bin\Setup"  

create a directory under bin called 'Setup'

Del "$(ProjectDir)bin\Setup\*.* /Q"

Deletes any existing items in the newly created bin

copy "$(TargetDir)*.dll"  "$(ProjectDir)bin\Setup"

Copies dll's from build location to the new setup location

Now if you are doing a build process where your 'Configuration Manager' is doing a different output for each environment and you just want each of them at all times you would probably need to traverse up a level, find those bins by their name of 'dev' or 'stg' and then copy them back. You may be able to create or list a variable that VS knows for the environment that matches to your JSON data as well.

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