| title | Quickstart for Adding Feature Flags to .NET/.NET Framework Apps |
|---|---|
| titleSuffix | Azure App Configuration |
| description | Find out how to implement feature flags in .NET and .NET Framework apps. See how to use feature management and Azure App Configuration for dynamic configuration. |
| services | azure-app-configuration |
| author | zhiyuanliang-ms |
| ms.service | azure-app-configuration |
| ms.devlang | csharp |
| ms.custom | devx-track-csharp, mode-other, devx-track-dotnet |
| ms.topic | quickstart |
| ms.tgt_pltfrm | .NET |
| ms.date | 07/25/2025 |
| ms.author | zhiyuanliang |
In this quickstart, you incorporate Azure App Configuration into a .NET or .NET Framework console app to create an end-to-end implementation of feature management. You can use App Configuration to centrally store all your feature flags and control their states.
The .NET feature management libraries extend .NET by providing feature flag support. These libraries are built on top of the .NET configuration system. They integrate with App Configuration through its .NET configuration provider.
- An Azure account with an active subscription. Create one for free.
- An App Configuration store, as shown in the quickstart for creating a store.
- Visual Studio.
- .NET SDK 8.0 or later for a .NET console app.
- .NET Framework 4.7.2 or later for a .NET Framework console app.
Add a feature flag called Beta to the App Configuration store and leave Label and Description with their default values. For more information about how to add feature flags to a store by using the Azure portal or the Azure CLI, see Create a feature flag.
:::image type="content" source="media/add-beta-feature-flag.png" alt-text="Screenshot of the Create a new feature flag dialog in the Azure portal. The name and key fields contain Beta. The label and description are blank." lightbox="media/add-beta-feature-flag.png":::
The app that you create in this quickstart connects to your App Configuration store to access your feature flag settings. To connect to App Configuration, your app can use Microsoft Entra ID or a connection string. Microsoft Entra ID is the recommended approach.
By default, the app that you create uses DefaultAzureCredential to authenticate to your App Configuration store. DefaultAzureCredential is a chain of token credentials. For authorization to work, you need to grant the App Configuration Data Reader role to the credential that your app uses. For instructions, see Authentication with token credentials. Allow sufficient time for the role assignment to propagate before running your app.
Your app uses an environment variable to establish the connection to App Configuration. Use one of the following commands to set an environment variable named Endpoint to the endpoint of your App Configuration store.
-
If you use Command Prompt, run the following command:
setx Endpoint "<endpoint-of-your-app-configuration-store>"Close and reopen Command Prompt so that the change takes effect. Verify that the environment variable is set by printing its value to the console.
-
If you use Windows PowerShell, run the following command:
[System.Environment]::SetEnvironmentVariable("Endpoint", "<endpoint-of-your-app-configuration-store>", "User")
Your app uses an environment variable to establish the connection to App Configuration. Use one of the following commands to set an environment variable named ConnectionString to the connection string of your App Configuration store.
-
If you use Command Prompt, run the following command:
setx ConnectionString "<connection-string-of-your-app-configuration-store>"Close and reopen Command Prompt so that the change takes effect. Verify that the environment variable is set by printing its value to the console.
-
If you use Windows PowerShell, run the following command:
[System.Environment]::SetEnvironmentVariable("ConnectionString", "<connection-string-of-your-app-configuration-store>", "User")
To use Visual Studio to create a new console app project, take the following steps.
-
Open Visual Studio. If it's already running, close and reopen it so that it recognizes the environment variable you set in the previous section.
-
In Visual Studio, select File > New > Project.
-
In the Create a new project dialog, enter Console into the search box.
- If you want to create a .NET app, select Console App, and then select Next.
- If you want to create a .NET Framework app, select Console App (.NET Framework), and then select Next.
-
In the Configure your new project dialog, enter a project name.
- If you want to create a .NET app, select Next to open the Additional information dialog. In that dialog, select a .NET framework, clear the Do not use top-level statements checkbox, and then select Create.
- If you want to create a .NET Framework app, select .NET Framework 4.7.2 or a later version under Framework, and then select Create.
To use the feature flag in your app, take the following steps.
-
In Solution Explorer, right-click your project, and then select Manage NuGet Packages.
-
On the Browse tab, search for and add the latest stable versions of the following NuGet packages to your project:
- Microsoft.Extensions.Configuration.AzureAppConfiguration
- Microsoft.FeatureManagement
- Azure.Identity
- Microsoft.Extensions.Configuration.AzureAppConfiguration
- Microsoft.FeatureManagement
-
Open Program.cs and add the following statements to the beginning of the file.
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration; using Microsoft.FeatureManagement; using Azure.Identity;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration; using Microsoft.FeatureManagement;
-
As shown in the following code blocks, update Program.cs by making three changes:
- To load feature flags from App Configuration, add a call to the
UseFeatureFlagsmethod. - To read feature flags from the configuration, create an instance of
FeatureManager. - Display a message if the Beta feature flag is enabled.
IConfiguration configuration = new ConfigurationBuilder() .AddAzureAppConfiguration(options => { string endpoint = Environment.GetEnvironmentVariable("Endpoint"); options.Connect(new Uri(endpoint), new DefaultAzureCredential()) .UseFeatureFlags(); }).Build(); var featureManager = new FeatureManager( new ConfigurationFeatureDefinitionProvider(configuration)); if (await featureManager.IsEnabledAsync("Beta")) { Console.WriteLine("Welcome to the beta!"); } Console.WriteLine("Hello World!");
public static async Task Main(string[] args) { IConfiguration configuration = new ConfigurationBuilder() .AddAzureAppConfiguration(options => { string endpoint = Environment.GetEnvironmentVariable("Endpoint"); options.Connect(new Uri(endpoint), new DefaultAzureCredential()) .UseFeatureFlags(); }).Build(); var featureManager = new FeatureManager( new ConfigurationFeatureDefinitionProvider(configuration)); if (await featureManager.IsEnabledAsync("Beta")) { Console.WriteLine("Welcome to the beta!"); } Console.WriteLine("Hello World!"); }
IConfiguration configuration = new ConfigurationBuilder() .AddAzureAppConfiguration(options => { options.Connect(Environment.GetEnvironmentVariable("ConnectionString")) .UseFeatureFlags(); }).Build(); var featureManager = new FeatureManager( new ConfigurationFeatureDefinitionProvider(configuration)); if (await featureManager.IsEnabledAsync("Beta")) { Console.WriteLine("Welcome to the beta!"); } Console.WriteLine("Hello World!");
public static async Task Main(string[] args) { IConfiguration configuration = new ConfigurationBuilder() .AddAzureAppConfiguration(options => { options.Connect(Environment.GetEnvironmentVariable("ConnectionString")) .UseFeatureFlags(); }).Build(); var featureManager = new FeatureManager( new ConfigurationFeatureDefinitionProvider(configuration)); if (await featureManager.IsEnabledAsync("Beta")) { Console.WriteLine("Welcome to the beta!"); } Console.WriteLine("Hello World!"); }
- To load feature flags from App Configuration, add a call to the
-
In Visual Studio, select Ctrl+F5 to build and run the application. The following output should appear in the console.
:::image type="content" source="./media/quickstarts/dotnet-app-feature-flag-disabled.png" alt-text="Screenshot of a Command Prompt window that contains output from the app. The output contains the text Hello World!":::
-
Sign in to the Azure portal. Select All resources, and then select your App Configuration store.
-
Select Feature manager and locate the Beta feature flag. Turn on the Enabled toggle to enable the flag.
-
Run the application again. The Beta message should appear in the console.
:::image type="content" source="./media/quickstarts/dotnet-app-feature-flag.png" alt-text="Screenshot of a Command Prompt window that contains output from the app. The output contains the text Welcome to the beta! and Hello World!":::
[!INCLUDE azure-app-configuration-cleanup]
In this quickstart, you created a feature flag in App Configuration and used it with a console app. To find out how to dynamically update feature flags and other configuration values without restarting the application, see the following tutorials:
[!div class="nextstepaction"] Use dynamic configuration in a .NET app
[!div class="nextstepaction"] Use dynamic configuration in a .NET Framework app
To enable feature management capability for other types of apps, see the following quickstarts:
[!div class="nextstepaction"] Add feature flags to an ASP.NET Core app
[!div class="nextstepaction"] Add feature flags to a .NET background service
For the full feature rundown of the .NET feature management library, see the following document:
[!div class="nextstepaction"] .NET feature management