Search code examples
c#asp.net-coreasp.net-core-mvcasp.net-core-cli

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?


Solution

  • 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.