Have a need to have a configuration file similar to previous web.config transforms. The end result is a single config file in the published target, or at runtime that has the relevant configuration settings based on the build configuration.
Typical scenario, an app progresses from local workstation => dev server => production server
We dont really want to mess with setting environment variables on each target machine, but would rather have a single config file used by the app.
Ok, you can do that with appsettings.json, but that implies doing this from the build system.
I know this defeats the original intent, that being appsettings.json + appsettings.{environmentname}.json, but Im curious what options there are to do this, other than using preprocessor directives?
I prefer to set an environment variable. For example, ASPNETCORE_ENVIRONMENT="Staging" on the staging servers. It takes a few seconds to do this and it done forever. Then you create different appsetting.json files that configure each environment;
appsettings.staging.json. This approach is very simple and very effective. With this set up you can simply deploy from Dev to Test and Test to Production rather than creating a build step which seems like what you are asking.
If you decide to create a custom solution then it is up to you to design and the write code.
Member
28 Points
469 Posts
Use appsettings.json with the build system so as not to need environment setting
Oct 26, 2019 01:25 PM|BitShift|LINK
Have a need to have a configuration file similar to previous web.config transforms. The end result is a single config file in the published target, or at runtime that has the relevant configuration settings based on the build configuration.
Typical scenario, an app progresses from local workstation => dev server => production server
We dont really want to mess with setting environment variables on each target machine, but would rather have a single config file used by the app.
Ok, you can do that with appsettings.json, but that implies doing this from the build system.
I know this defeats the original intent, that being appsettings.json + appsettings.{environmentname}.json, but Im curious what options there are to do this, other than using preprocessor directives?
All-Star
53001 Points
23594 Posts
Re: Use appsettings.json with the build system so as not to need environment setting
Oct 26, 2019 03:25 PM|mgebhard|LINK
I prefer to set an environment variable. For example, ASPNETCORE_ENVIRONMENT="Staging" on the staging servers. It takes a few seconds to do this and it done forever. Then you create different appsetting.json files that configure each environment; appsettings.staging.json. This approach is very simple and very effective. With this set up you can simply deploy from Dev to Test and Test to Production rather than creating a build step which seems like what you are asking.
If you decide to create a custom solution then it is up to you to design and the write code.