'Azure App Service - inject appsettings.production.json
Is there a convenient way to provide an entire appsettings.production.json file to a containerized app service in Azure ?
Specifically, I want the entire file to live somewhere, relatively securely, on azure and then be injected as config to my web app in some clever way. I've considered App Configuration instances, Key Vaults etc, but neither of them can import the appsettings.json format in a seamless copy-paste way (App Configuration actually has the import button wherein appsettings.json is supported, but once imported it's a laborious process to manage it going forward as you're back to clicking your way in an item by item fashion, there isn't even a bulk delete method).
I do not want to manually have to translate the entire json structure i.e. to f.ex. the Configuration pane.
To reiterate: I don't want the production.json to be part of the publish pipeline in any way but rather that it lives somewhere separately on azure and gets injected at application startup
Solution 1:[1]
Azure App Service - inject appsettings.production.json
- In
project.jsonfile , ensure thatpublishOptions/includecontainsappsettings.Production.json - The
IHostingEnvironmentcan be used to load various appsettings. json files per-environment.
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
- We can load another JSON file with an environment specific name and with
optionalset to true. - Make sure that both
appsettings.jsonandappsettings.Production.jsonare deployed. Add the production file inProject.json
{
...
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"appsettings.Production.json",
"web.config"
]
},
...
}
- Add
ASPNETCORE_ENVIRONMENT = Production
as an envrionment variable to your Azure App Service using the Azure Portal =>Your Web App=> Configuration => App Settings.
provide an entire appsettings.production.json file to a containerized app service in Azure
- By default, ASP.NET Core uses appsettings_.json_ configuration files, but it also supports using environment variables.
- For local development, store application secrets locally in the secrets.json file. To view this file, right-click on your project and select Manage User Secrets.
Refer Use your environment to store configuration data
Please refer Configure an App Service app and appsettings.json for more information
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HarshithaVeeramalla-MT |
