title | description | services | documentationcenter | author | editor | ms.assetid | ms.service | ms.devlang | ms.custom | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Quickstart for adding feature flags to .NET Framework apps | Microsoft Docs | Microsoft Docs |
A quickstart for adding feature flags to .NET Framework apps and managing them in Azure App Configuration |
azure-app-configuration |
AlexandraKemperMS |
azure-app-configuration |
csharp |
devx-track-csharp, mode-other |
quickstart |
.NET |
tbd |
10/19/2020 |
alkemper |
In this quickstart, you incorporate Azure App Configuration into a .NET Framework app to create an end-to-end implementation of feature management. You can use the App Configuration service to centrally store all your feature flags and control their states.
The .NET Feature Management libraries extend the framework with feature flag support. These libraries are built on top of the .NET configuration system. They integrate with App Configuration through its .NET configuration provider.
- Azure subscription - create one for free
- Visual Studio 2019
- .NET Framework 4.8
[!INCLUDE azure-app-configuration-create]
-
Select Feature Manager > +Add to add a feature flag called
Beta
.Leave
label
undefined for now.
-
Start Visual Studio, and select File > New > Project.
-
In Create a new project, filter on the Console project type and click on Console App (.NET Framework). Click Next.
-
In Configure your new project, enter a project name. Under Framework, select .NET Framework 4.8 or higher. Click Create.
-
Right-click your project, and select Manage NuGet Packages. On the Browse tab, search and add the following NuGet packages to your project.
Microsoft.Extensions.DependencyInjection Microsoft.Extensions.Configuration.AzureAppConfiguration Microsoft.FeatureManagement
-
Open Program.cs and add the following statements:
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration; using Microsoft.FeatureManagement; using System.Threading.Tasks;
-
Update the
Main
method to connect to App Configuration, specifying theUseFeatureFlags
option so that feature flags are retrieved. Then display a message if theBeta
feature flag is enabled.public static async Task Main(string[] args) { IConfigurationRoot configuration = new ConfigurationBuilder() .AddAzureAppConfiguration(options => { options.Connect(Environment.GetEnvironmentVariable("ConnectionString")) .UseFeatureFlags(); }).Build(); IServiceCollection services = new ServiceCollection(); services.AddSingleton<IConfiguration>(configuration).AddFeatureManagement(); using (ServiceProvider serviceProvider = services.BuildServiceProvider()) { IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>(); if (await featureManager.IsEnabledAsync("Beta")) { Console.WriteLine("Welcome to the beta!"); } } Console.WriteLine("Hello World!"); Console.WriteLine("Press any key to continue ..."); Console.Read(); }
-
Set an environment variable named ConnectionString to the connection string of your App Configuration store. If you use the Windows command prompt, 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"
-
Restart Visual Studio to allow the change to take effect.
-
Press Ctrl + F5 to build and run the console app.
[!INCLUDE azure-app-configuration-cleanup]
In this quickstart, you created a feature flag in App Configuration and used it with a .NET Framework console app. To learn how to dynamically update feature flags and other configuration values without restarting the application, continue to the next tutorial.
[!div class="nextstepaction"] Enable dynamic configuration