Quickstart: Create a .NET app with App Configuration

In this quickstart, you incorporate Azure App Configuration into a .NET console app to centralize storage and management of application settings separate from your code.

Prerequisites

Add a key-value

Add the following key-value to the App Configuration store and leave Label and Content Type with their default values. For more information about how to add key-values to a store using the Azure portal or the CLI, go to Create a key-value.

Key Value
TestApp:Settings:Message Data from Azure App Configuration

Create a .NET console app

You can use the .NET command-line interface (CLI) to create a new .NET console app project. The advantage of using the .NET CLI over Visual Studio is that it's available across the Windows, macOS, and Linux platforms. Alternatively, use the preinstalled tools available in the Azure Cloud Shell.

  1. Create a new folder for your project.

  2. In the new folder, run the following command to create a new .NET console app project:

    dotnet new console
    

Connect to an App Configuration store

  1. Add a reference to the Microsoft.Extensions.Configuration.AzureAppConfiguration NuGet package by running the following command:

    dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
    
  2. Run the following command to restore packages for your project:

    dotnet restore
    
  3. Open Program.cs, and add the following statements:

    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.Configuration.AzureAppConfiguration;
    
  4. Use App Configuration by calling the AddAzureAppConfiguration method in the Program.cs file.

    var builder = new ConfigurationBuilder();
    builder.AddAzureAppConfiguration(Environment.GetEnvironmentVariable("ConnectionString"));
    
    var config = builder.Build();
    Console.WriteLine(config["TestApp:Settings:Message"] ?? "Hello world!");
    

Build and run the app locally

  1. Set an environment variable named ConnectionString, and set it to the access key to your App Configuration store. At the command line, run the following command:

    To build and run the app locally using the Windows command prompt, run the following command:

    setx ConnectionString "connection-string-of-your-app-configuration-store"
    

    Restart the command prompt to allow the change to take effect. Print the value of the environment variable to validate that it's set properly.

  2. Run the following command to build the console app:

    dotnet build
    
  3. After the build successfully completes, run the following command to run the app locally:

    dotnet run
    

Clean up resources

If you don't want to continue using the resources created in this article, delete the resource group you created here to avoid charges.

Important

Deleting a resource group is irreversible. The resource group and all the resources in it are permanently deleted. Ensure that you don't accidentally delete the wrong resource group or resources. If you created the resources for this article inside a resource group that contains other resources you want to keep, delete each resource individually from its respective pane instead of deleting the resource group.

  1. Sign in to the Azure portal, and select Resource groups.
  2. In the Filter by name box, enter the name of your resource group.
  3. In the result list, select the resource group name to see an overview.
  4. Select Delete resource group.
  5. You're asked to confirm the deletion of the resource group. Enter the name of your resource group to confirm, and select Delete.

After a few moments, the resource group and all its resources are deleted.

Next steps

In this quickstart, you created a new App Configuration store and used it with a .NET console app via the App Configuration provider. To learn how to configure your .NET app to dynamically refresh configuration settings, continue to the next tutorial.