I have a Web API in .NET 6 that uses the standard IConfiguration
to get config/settings values from appsettings.json
and is deployed to Azure App Service (Windows).
I'm deploying it with Visual Studio and I can see the code being updated in App Service. However, my changes in the appsettings.json
were not reflected in the App Settings tab of the Environment variables page (in the Settings section). Note that the appsettings.json
inside App Service was updated (I verified this with Kudu).
I don't know how the previous developer created those environment variables (one for each value in appsettings.json
).
appsettings.json
and create the corresponding environment variables?appsettings.json
by right-clicking on it in Visual Studio Solution Explorer and then clicking on the Publishing appsettings.json
menu item, but that didn't seem to work. Am I using that menu item incorrectly?appsettings.json
. I know that for some settings (e.g., sensitive values like tokens/API keys), it might be a way to avoid having those values on disk, but in this project, every single setting is being duplicated. Is this a common/standard thing to do? I usually just copy/deploy all the appsettings.<env name>.json
for each environment and just set the ASPNETCORE_ENVIRONMENT
variable to match the <env name>
.Answers to any/all questions above will be appreciated, I've read several documentation pages of Azure App Service and none mention of a tool/way to automate creating as may env vars as I have in this project. I want to think that the previous developer was not crazy enough to manually create/keep updated each one manually.
The configuration which is set in the appsettings.json
will not be added/seen in the Environment variables section of App Service.
appsettings.json
file value in KUDU => site/wwwroot
folder.I don't know how the previous developer created those environment variables
appsettings.json
fileappsettings.json
in Local:
"SampleConfig": "Value from Development appsettings.json"
IConfiguration
. private readonly ILogger<WeatherForecastController> _logger;
private readonly IConfiguration myconfig;
public WeatherForecastController(ILogger<WeatherForecastController> logger,IConfiguration config)
{
_logger = logger;
myconfig = config;
}
var mysetting= myconfig["SampleConfig"];
Output of my app with values from appsettings.json
:
Is there a tool to automate the mirroring of the new entries in
appsettings.json
and create the corresponding environment variables?
Azure CLI
Command.I have followed this MSDoc for CLI Commands.
az login
az webapp config appsettings set --name AppSettings6June --resource-group YourRGName --settings "SampleConfig=Value from Deployed Azure App Service" "Name=Harshitha" "Title=Azure App Service"
OR
json
file(create new file or edit the existing appsettings.json) and run the below command.az webapp config appsettings set --name AppSettings6June --resource-group YourRGName --settings "@appsettings.json"
My appsettings.json
:
{
"SampleConfig": "Value from Deployed Azure App Service",
"Name": "Harshitha",
"Title": "Azure App Service"
}
Azure Environment Variables :
App Service Output :
I see that there is a "Pull reference values" button in the Environment variables page, from the few Google results, it seems like that would be to pull updated values from Key Vault. Is this correct?