Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing appsettings.json to different environment

I have three files appsettings.json which is a file that I want to store "general shared settings", then I have appsettings.Development.json and appsettings.Production.json.

When I do a publish from Visual Studio, it seems like only appsettings.json is copied and not adding / merge or even just send a simple copy the deployment folder, to me this task should be incorporated into the deployment pipeline.

The question is: how can I do it? What am I missing? Is it not supposed that these actions should be already be incorporated in the process?

like image 731
pedrommuller Avatar asked Aug 02 '16 01:08

pedrommuller


People also ask

Can we have multiple Appsettings json?

Of course, we can add and use multiple appsettings. json files in ASP.NET Core project. To configure and read data from your custom json files, you can refer to the following code snippet.

What is difference between Appsettings json and Appsettings development json?

NET Core and as far as I see from my search on the web, appsettings.Development. json is used for development config while developing the app and appsettings. Production. json is used on the published app in production server.


1 Answers

Make sure your project.json has those files included in the list of files to publish and/or copy to output:

"buildOptions": {
  "copyToOutput": [
    ...
    "appsettings.json",
    "appsettings.*.json",
    ...
  ],
}

or

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

The files will not be merged in a single file. They will be logically merged at runtime by the configuration system.

like image 72
Victor Hurdugaci Avatar answered Sep 28 '22 12:09

Victor Hurdugaci