title | description | services | author | ms.service | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|
Quickstart for Azure App Configuration with .NET Core | Microsoft Docs |
A quickstart for using Azure App Configuration with .NET Core apps |
azure-app-configuration |
lisaguthrie |
azure-app-configuration |
quickstart |
1/9/2019 |
lcozzens |
In this quickstart, you incorporate Azure App Configuration into a .NET Core console app to centralize storage and management of application settings separate from your code.
- Azure subscription - create one for free
- .NET Core SDK - also available in the Azure Cloud Shell.
[!INCLUDE azure-app-configuration-create]
-
Select Configuration Explorer > Create > Key-value to add the following key-value pairs:
Key Value TestApp:Settings:Message Data from Azure App Configuration Leave Label and Content Type empty for now.
-
Select Apply.
You use the .NET Core command-line interface (CLI) to create a new .NET Core console app project. The advantage of using the .NET Core 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.
-
Create a new folder for your project.
-
In the new folder, run the following command to create a new ASP.NET Core console app project:
dotnet new console
-
Add a reference to the
Microsoft.Extensions.Configuration.AzureAppConfiguration
NuGet package by running the following command:dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
-
Run the following command to restore packages for your project:
dotnet restore
-
Open Program.cs, and add a reference to the .NET Core App Configuration provider.
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration;
-
Update the
Main
method to use App Configuration by calling thebuilder.AddAzureAppConfiguration()
method.static void Main(string[] args) { var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration(Environment.GetEnvironmentVariable("ConnectionString")); var config = builder.Build(); Console.WriteLine(config["TestApp:Settings:Message"] ?? "Hello world!"); }
-
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:
setx ConnectionString "connection-string-of-your-app-configuration-store"
If you use Windows PowerShell, run the following command:
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
If you use macOS or Linux, run the following command:
export ConnectionString='connection-string-of-your-app-configuration-store'
Restart the command prompt to allow the change to take effect. Print out the value of the environment variable to validate that it is set properly.
-
Run the following command to build the console app:
dotnet build
-
After the build successfully completes, run the following command to run the app locally:
dotnet run
[!INCLUDE azure-app-configuration-cleanup]
In this quickstart, you created a new App Configuration store and used it with a .NET Core console app via the App Configuration provider. To learn how to configure your .NET Core app to dynamically refresh configuration settings, continue to the next tutorial.
[!div class="nextstepaction"] Enable dynamic configuration