In this article, let’s create a .NET console application to retrieve configuration settings from Azure App Configuration using the .NET client library. Azure CLI is used to create an Azure app configuration resource and to store configuration settings. Configuration values are retrieved using ConfigurationBuilder. After this exercise, one will be able to organize the settings with hierarchical keys and application authentication to access Microsoft cloud-based configuration data.
The following tasks are performed:
Create Azure App Configuration resources using the Azure CLI.
Assign role to Microsoft Entra (Azure AD) user
Add configuration information using Azure CLI.
Retrieve configuration details using the .NET Client Library.
Sign in to Azure and run the application.
Clean up resources.
Create an Azure App Configuration resource using Azure CLI
The first basic task is to create and prepare Azure app configuration resources. Azure CLI (Azure Cloud Shell) is used to create the required resources. Azure CLI is a free Bash shell that can be run directly within the Azure portal. That is preinstalled and configured within the account. Perform the steps below one by one to achieve this. These steps are almost the same except for a few changes, as mentioned in the previous article How to Create and Retrieve Secrets from Azure Key Vault using Azure CLI?
Use Azure CLI (Azure Cloud Shell)
It is a free Bash shell which can be run directly within the Azure portal. It is preinstalled and configured within an account.
Click Cloud Shell button on the menu bar at the top right side of the Azure portal.

It will launch an interactive shell which can be used to run the steps outlined in this article. Select a Bash environment. To use code editor In cloud shell toolbar go to Settings menu and then select Go to Classic version.

Create resource group
Resource group is a logical container used to hold related resources. In it include the resources which you want to manage as a group. App configuration resource belongs to this resource group. Create it using az group create command.
az group create \
--name myResourceGroup1 \
--location eastus2 eastus2 is location code instead of it one can use their nearest region location.
Register Namespaces
Microsoft.AppConfiguration namespace is required to registered for the application. az provider register command is used to register namespaces as like below. This command will take few minutes to complete the registration process.
az provider register --namespace Microsoft.AppConfigurationCreate Azure App Configuration resource
az appconfig create command is used as mentioned below to create an Azure app configuration resource. It will take few minutes to complete the process.
az appconfig create
--location eastus2 \
--name appConfigName1 \
--resource-group myResourceGroup1\
--sku FreeAssign role to Microsoft Entra (Azure AD) user
It is important to assign roles to Microsoft Entra (Azure AD) user name. Roles will define what access and permissions a user has within an organization’s Microsoft cloud environment. Roles determine what resources and actions a user can perform. “App Configuration Data Reader” role is to be assigned to Microsoft Entra user. It gives permissions to retrieve configuration settings to user account. One by one perform below steps in Azure CLI.
Retrieve userPrincipalName
First, retrieve userPrincipalName from account as mentioned in following command. It retrieves the information about currently authenticated user including their UPN and represents that who the role will be assigned to.
userPrincipal=$(az rest
--method GET
--url https://graph.microsoft.com/v1.0/me \
--headers 'Content-Type=application/json' \
--query userPrincipalName
--output tsv)Retrieve resource ID
Second, get the resource ID of key vault using below command. This will be used in next step to set scope for role assignment. Resource ID sets scope for role assignment to specific key vault.
resourceID=$(az appconfig show \
--resource-group myResourceGroup1 \
--name appConfigName1\
--query id \
--output tsv)Create and assign App Configuration Data Reader role
Finally, create and assign App Configuration Data Reader role using az role assignment create command. This will give permissions to manage next routines. userPrincipal and resourceID variables are created in first and second steps which are used in this command to retrieve actual value at command execution time.
az role assignment create \
--assignee $userPrincipal\
--role "App Configuration Data Reader" \
--scope $resourceIDNow, required basic resources are deployed and ready to use in console application.
Add configuration information using Azure CLI
Let’s add connection sting into App configuration using Azure CLI and than retrieve it using .NET SDK. az appconfig kv set command is used to create or update the key-value pair in Azure App Configuration store. Following example sets configuration value for the development environment.
az appconfig kv set \
--name appConfigName1 \
--key Dev:conStruction \
--value "Under Construction"\
--yes
Join the conversation! Your thoughts help the community grow.