Azure App Config - Conditional

Rajarajacholan Krishnamurthy 21 Reputation points
2022-08-17T12:48:54.393+00:00

How can I let my application to use appsettings.json file when I run it on my local computer and use Azure App Config keys when it is deployed in cloud?

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
206 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Udaiappa Ramachandran 726 Reputation points MVP
    2022-08-17T21:32:35.5+00:00

    I assume you are referring to .NET core applications; if so you can use appsettings.Development.json for local dev

    var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", false, true)
    .AddEnvironmentVariables();

    if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development)
    {
    builder.AddJsonFile("appsettings.Development.json");
    }

    232183-image.png

    0 comments No comments