azureazure-web-app-serviceappsettingsazure-deployment

Environment variables for app settings in Azure App Service


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

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.


Solution

  • The configuration which is set in the appsettings.json will not be added/seen in the Environment variables section of App Service.

    I don't know how the previous developer created those environment variables

    enter image description here

    appsettings.json in Local:

      "SampleConfig": "Value from Development appsettings.json"
    
     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:

    enter image description here

    Is there a tool to automate the mirroring of the new entries in appsettings.json and create the corresponding environment variables?

    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"
    

    enter image description here

    OR

    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"
    }
    

    enter image description here

    Azure Environment Variables :

    enter image description here

    App Service Output :

    enter image description here

    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?

    Refer this MSDoc and my SOThread for more details.