You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Customer intent: As a .NET Framework developer, I want to use feature flags to control feature availability quickly and confidently.
12
+
ms.date: 2/19/2024
13
+
ms.author: zhiyuanliang
14
+
#Customer intent: As a .NET developer, I want to use feature flags to control feature availability quickly and confidently.
14
15
---
15
-
# Quickstart: Add feature flags to a .NET Framework console app
16
+
# Quickstart: Add feature flags to a .NET/.NET Framework console app
16
17
17
-
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.
18
+
In this quickstart, you incorporate Azure App Configuration into a .NET console 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.
18
19
19
20
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.
20
21
21
22
## Prerequisites
22
23
23
24
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/).
24
25
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
25
-
-[Visual Studio 2019](https://visualstudio.microsoft.com/vs)
@@ -32,15 +40,80 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
32
40
> [!div class="mx-imgBorder"]
33
41
> 
34
42
35
-
## Create a .NET Framework console app
43
+
## Create a .NET console app
44
+
45
+
### [.NET](#tab/dotnet)
46
+
47
+
You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) 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](https://shell.azure.com).
48
+
49
+
1. Create a new folder for your project.
50
+
51
+
1. In the new folder, run the following command to create a new .NET console app project:
1. In **Create a new project**, filter on the **Console** project type and click on **Console App (.NET Framework)**. Click **Next**.
40
62
41
63
1. In **Configure your new project**, enter a project name. Under **Framework**, select **.NET Framework 4.8** or higher. Click **Create**.
42
64
43
-
## Connect to an App Configuration store
65
+
---
66
+
67
+
## Use feature flag
68
+
69
+
### [.NET](#tab/dotnet)
70
+
71
+
1. Add references to the `Microsoft.Extensions.Configuration.AzureAppConfiguration` and `Microsoft.FeatureManagement` NuGet packages by running the following commands.
1. Run the following command to restore packages for your project.
79
+
80
+
```dotnetcli
81
+
dotnet restore
82
+
```
83
+
84
+
1. Open *Program.cs* and add the following statements.
85
+
86
+
```csharp
87
+
using Microsoft.Extensions.Configuration;
88
+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
89
+
using Microsoft.FeatureManagement;
90
+
```
91
+
92
+
1. Connect to App Configuration, specifying the `UseFeatureFlags` option so that feature flags are retrieved. Create a `ConfigurationFeatureDefinitionProvider` to provide feature flag definition from the configuration and a `FeatureManager` to evaluate feature flags' state. Then display a message if the `Beta` feature flag is enabled.
93
+
94
+
```csharp
95
+
IConfiguration configuration = new ConfigurationBuilder()
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
103
+
104
+
IFeatureManager featureManager = new FeatureManager(
105
+
featureDefinitionProvider,
106
+
new FeatureManagementOptions());
107
+
108
+
if (await featureManager.IsEnabledAsync("Beta"))
109
+
{
110
+
Console.WriteLine("Welcome to the beta!");
111
+
}
112
+
113
+
Console.WriteLine("Hello World!");
114
+
```
115
+
116
+
### [.NET Framework](#tab/dotnet-framework)
44
117
45
118
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the following NuGet packages to your project.
46
119
@@ -49,7 +122,7 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
49
122
Microsoft.FeatureManagement
50
123
```
51
124
52
-
1. Open *Program.cs* and add the following statements:
125
+
1. Open *Program.cs* and add the following statements.
53
126
54
127
```csharp
55
128
using Microsoft.Extensions.Configuration;
@@ -82,28 +155,88 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
82
155
}
83
156
84
157
Console.WriteLine("Hello World!");
85
-
Console.WriteLine("Press any key to continue ...");
86
-
Console.Read();
87
158
}
88
159
```
89
160
161
+
---
162
+
90
163
## Build and run the app locally
91
164
92
-
1. 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:
165
+
1. 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.
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.
204
+
205
+
---
206
+
207
+
1. Build and run the application.
208
+
209
+
### [.NET](#tab/dotnet)
210
+
211
+
- Run the following command to build the console app.
212
+
213
+
```dotnetcli
214
+
dotnet build
215
+
```
216
+
217
+
- After the build successfully completes, run the following command to run the app locally.
218
+
219
+
```dotnetcli
220
+
dotnet run
221
+
```
222
+
223
+
### [.NET Framework](#tab/dotnet-framework)
224
+
225
+
- Restart Visual Studio to allow the change to take effect.
226
+
227
+
- Press Ctrl + F5 to build and run the console app.
228
+
229
+
---
230
+
231
+
1. You should see the following outputs in the console.
232
+
233
+

234
+
235
+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created previously.
236
+
237
+
1. Select **Feature manager** and locate the **Beta** feature flag. Enable the flag by selecting the checkbox under **Enabled**.
105
238
106
-
1. Press Ctrl + F5 to build and run the console app.
239
+
1. Run the application again. You should see the Beta message in the console.
107
240
108
241

0 commit comments