Quickstart: Create a .NET Framework app with Azure App Configuration
Article
There are two ways to incorporate Azure App Configuration into a .NET Framework-based app.
The configuration builder for App Configuration enables data from App Configuration to be loaded to App Settings. Your app accesses configuration as it always does via ConfigurationManager. You don't need to make any code change other than updates to app.config or web.config files. This quickstart walks you through this option.
As is designed by the .NET Framework, the App Settings can only refresh upon application restart. The App Configuration .NET provider is a .NET Standard library. It supports caching and refreshing configuration dynamically without application restart. If the dynamic configuration is essential to you and you're willing to make code changes, see tutorials on how you can implement dynamic configuration updates in a .NET Framework console app or an ASP.NET web app.
In this quickstart, a .NET Framework console app is used as an example, but the same technique applies to an ASP.NET Web Forms/MVC app.
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 Framework console app
Start Visual Studio and select Create a new project.
In Create a new project, filter on the Console project type and select Console App (.NET Framework) with C# from the project template list. Press Next.
In Configure your new project, enter a project name. Under Framework, select .NET Framework 4.7.2 or higher. Press Create.
Connect to an App Configuration store
Connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
Right-click your project, and select Manage NuGet Packages. On the Browse tab, search and add the latest stable versions of following NuGet packages to your project.
Update the App.config file of your project as follows. You can connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
The DefaultAzureCredential is used to authenticate to your App Configuration store by default. Follow the instructions to assign your credential the App Configuration Data Reader role. Be sure to allow sufficient time for the permission to propagate before running your application.
XML
<configSections><sectionname="configBuilders"type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"restartOnExternalChanges="false"requirePermission="false" /></configSections><configBuilders><builders><addname="MyConfigStore"mode="Greedy"endpoint="${Endpoint}"type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" /><addname="Environment"mode="Greedy"type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" /></builders></configBuilders><appSettingsconfigBuilders="Environment,MyConfigStore"><addkey="AppName"value="Console App Demo" /><addkey="Endpoint"value ="Set via an environment variable - for example, dev, test, staging, or production endpoint." /></appSettings>
The endpoint value of your App Configuration store is read from the environment variable Endpoint. You also add the Environment configuration builder before the MyConfigStore in the configBuilders property of the appSettings section.
XML
<configSections><sectionname="configBuilders"type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"restartOnExternalChanges="false"requirePermission="false" /></configSections><configBuilders><builders><addname="MyConfigStore"mode="Greedy"connectionString="${ConnectionString}"type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" /><addname="Environment"mode="Greedy"type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" /></builders></configBuilders><appSettingsconfigBuilders="Environment,MyConfigStore"><addkey="AppName"value="Console App Demo" /><addkey="ConnectionString"value ="Set via an environment variable - for example, dev, test, staging, or production connection string." /></appSettings>
The connection string of your App Configuration store is read from the environment variable ConnectionString. You also add the Environment configuration builder before the MyConfigStore in the configBuilders property of the appSettings section.
Open Program.cs, and update the Main method to use App Configuration by calling ConfigurationManager.
Set an environment variable named ConnectionString to the read-only connection string of your App Configuration store found under Access settings of your store in the Azure portal.
If you use the Windows command prompt, run the following command:
Restart Visual Studio to allow the change to take effect.
Press Ctrl + F5 to build and run the console app. You should see the message from App Configuration outputs in the console.
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.
Sign in to the Azure portal, and select Resource groups.
In the Filter by name box, enter the name of your resource group.
In the result list, select the resource group name to see an overview.
Select Delete resource group.
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 Framework console app. To learn how to enable your .NET Framework app to dynamically refresh configuration settings, continue to the next tutorials.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.