Skip to content

Commit 5a27b12

Browse files
authored
Merge pull request #266635 from zhiyuanliang-ms/zhiyuanliang/unify-dotnet-console-example
Azure App Configuration - Add .NET Console app example
2 parents ba1eb32 + 8354395 commit 5a27b12

File tree

6 files changed

+105
-51
lines changed

6 files changed

+105
-51
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
items:
3434
- name: ASP.NET Core
3535
href: quickstart-feature-flag-aspnet-core.md
36-
- name: .NET Framework
36+
- name: .NET/.NET Framework
3737
href: quickstart-feature-flag-dotnet.md
3838
- name: Java Spring
3939
href: quickstart-feature-flag-spring-boot.md

articles/azure-app-configuration/index.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ landingContent:
136136
links:
137137
- text: ASP.NET Core app
138138
url: quickstart-feature-flag-aspnet-core.md
139-
- text: .NET app
140-
url: use-feature-flags-dotnet-core.md
141-
- text: .NET Framework app
139+
- text: .NET/.NET Framework app
142140
url: quickstart-feature-flag-dotnet.md
143141
- text: Spring Boot app
144142
url: quickstart-feature-flag-spring-boot.md
17.1 KB
Loading
-2.54 KB
Loading

articles/azure-app-configuration/quickstart-dotnet-core-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Add the following key-value to the App Configuration store and leave **Label** a
3131

3232
## Create a .NET console app
3333

34-
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).
34+
You can 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).
3535

3636
1. Create a new folder for your project.
3737

Lines changed: 102 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
---
2-
title: Quickstart for adding feature flags to .NET Framework apps | Microsoft Docs | Microsoft Docs
3-
description: A quickstart for adding feature flags to .NET Framework apps and managing them in Azure App Configuration
2+
title: Quickstart for adding feature flags to .NET/.NET Framework apps
3+
titleSuffix: Azure App Configuration
4+
description: A quickstart for adding feature flags to .NET/.NET Framework apps and managing them in Azure App Configuration.
45
services: azure-app-configuration
5-
author: maud-lv
6+
author: zhiyuanliang
67
ms.service: azure-app-configuration
78
ms.devlang: csharp
89
ms.custom: devx-track-csharp, mode-other, devx-track-dotnet
910
ms.topic: quickstart
1011
ms.tgt_pltfrm: .NET
11-
ms.date: 3/20/2023
12-
ms.author: malev
13-
#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.
1415
---
15-
# Quickstart: Add feature flags to a .NET Framework console app
16+
# Quickstart: Add feature flags to a .NET/.NET Framework console app
1617

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.
1819

1920
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.
2021

2122
## Prerequisites
2223

2324
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/).
2425
- 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)
26-
- [.NET Framework 4.8](https://dotnet.microsoft.com/download)
26+
- [Visual Studio](https://visualstudio.microsoft.com/downloads)
27+
- [.NET SDK 6.0 or later](https://dotnet.microsoft.com/download) for .NET console app.
28+
- [.NET Framework 4.7.2 or later](https://dotnet.microsoft.com/download/dotnet-framework) for .NET Framework console app.
2729

2830
## Add a feature flag
2931

@@ -32,15 +34,17 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
3234
> [!div class="mx-imgBorder"]
3335
> ![Enable feature flag named Beta](media/add-beta-feature-flag.png)
3436
35-
## Create a .NET Framework console app
37+
## Create a console app
38+
39+
You can use Visual Studio to create a new console app project.
3640

3741
1. Start Visual Studio, and select **File** > **New** > **Project**.
3842

39-
1. In **Create a new project**, filter on the **Console** project type and click on **Console App (.NET Framework)**. Click **Next**.
43+
1. In **Create a new project**, filter on the **Console** project type and select **Console App**. If you want to create a .NET Framework app, please select **Console App (.NET Framework)** instead. Click **Next**.
4044

41-
1. In **Configure your new project**, enter a project name. Under **Framework**, select **.NET Framework 4.8** or higher. Click **Create**.
45+
1. In **Configure your new project**, enter a project name. If you are creating a .NET Framework app, please select **.NET Framework 4.7.2** or higher under **Framework**. Click **Create**.
4246

43-
## Connect to an App Configuration store
47+
## Use the feature flag
4448

4549
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the following NuGet packages to your project.
4650

@@ -49,61 +53,108 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
4953
Microsoft.FeatureManagement
5054
```
5155
52-
1. Open *Program.cs* and add the following statements:
56+
Make sure that the version of `Microsoft.FeatureManagement` is greater than 3.1.0.
57+
58+
1. Open *Program.cs* and add the following statements.
5359
5460
```csharp
5561
using Microsoft.Extensions.Configuration;
5662
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
5763
using Microsoft.FeatureManagement;
58-
using System.Threading.Tasks;
5964
```
6065
61-
1. Update the `Main` method to connect to App Configuration, specifying the `UseFeatureFlags` option so that feature flags are retrieved. Create a `ConfigurationFeatureDefinitionProvider` to provide feature flag definitions from the configuration and a `FeatureManager` to evaluate feature flags' state. Then display a message if the `Beta` feature flag is enabled.
66+
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.
67+
68+
### [.NET](#tab/dotnet)
6269
6370
```csharp
64-
public static async Task Main(string[] args)
65-
{
66-
IConfiguration configuration = new ConfigurationBuilder()
67-
.AddAzureAppConfiguration(options =>
68-
{
69-
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
70-
.UseFeatureFlags();
71-
}).Build();
72-
73-
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
74-
75-
IFeatureManager featureManager = new FeatureManager(
76-
featureDefinitionProvider,
77-
new FeatureManagementOptions());
78-
79-
if (await featureManager.IsEnabledAsync("Beta"))
71+
IConfiguration configuration = new ConfigurationBuilder()
72+
.AddAzureAppConfiguration(options =>
73+
{
74+
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
75+
.UseFeatureFlags();
76+
}).Build();
77+
78+
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
79+
80+
IFeatureManager featureManager = new FeatureManager(
81+
featureDefinitionProvider,
82+
new FeatureManagementOptions());
83+
84+
if (await featureManager.IsEnabledAsync("Beta"))
85+
{
86+
Console.WriteLine("Welcome to the beta!");
87+
}
88+
89+
Console.WriteLine("Hello World!");
90+
```
91+
92+
### [.NET Framework](#tab/dotnet-framework)
93+
94+
```csharp
95+
public static async Task Main(string[] args)
96+
{
97+
IConfiguration configuration = new ConfigurationBuilder()
98+
.AddAzureAppConfiguration(options =>
8099
{
81-
Console.WriteLine("Welcome to the beta!");
82-
}
100+
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
101+
.UseFeatureFlags();
102+
}).Build();
103+
104+
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
83105
84-
Console.WriteLine("Hello World!");
85-
Console.WriteLine("Press any key to continue ...");
86-
Console.Read();
106+
IFeatureManager featureManager = new FeatureManager(
107+
featureDefinitionProvider,
108+
new FeatureManagementOptions());
109+
110+
if (await featureManager.IsEnabledAsync("Beta"))
111+
{
112+
Console.WriteLine("Welcome to the beta!");
87113
}
114+
115+
Console.WriteLine("Hello World!");
116+
}
88117
```
89118
119+
---
120+
90121
## Build and run the app locally
91122
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:
123+
1. Set an environment variable named **ConnectionString** to the connection string of your App Configuration store.
124+
125+
### [Windows command prompt](#tab/windowscommandprompt)
126+
127+
If you use the Windows command prompt, run the following command.
93128
94129
```console
95-
setx ConnectionString "connection-string-of-your-app-configuration-store"
130+
setx ConnectionString "connection-string-of-your-app-configuration-store"
96131
```
97132
98-
If you use Windows PowerShell, run the following command:
133+
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.
134+
135+
### [PowerShell](#tab/powershell)
136+
137+
If you use Windows PowerShell, run the following command.
99138
100-
```powershell
101-
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
139+
```azurepowershell
140+
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
102141
```
103142
143+
---
144+
104145
1. Restart Visual Studio to allow the change to take effect.
105146
106-
1. Press Ctrl + F5 to build and run the console app.
147+
1. Press Ctrl + F5 to build and run the application.
148+
149+
1. You should see the following outputs in the console.
150+
151+
![App with feature flag disabled](./media/quickstarts/dotnet-app-feature-flag-disabled.png)
152+
153+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created previously.
154+
155+
1. Select **Feature manager** and locate the **Beta** feature flag. Enable the flag by selecting the checkbox under **Enabled**.
156+
157+
1. Run the application again. You should see the Beta message in the console.
107158
108159
![App with feature flag enabled](./media/quickstarts/dotnet-app-feature-flag.png)
109160
@@ -113,7 +164,12 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
113164
114165
## Next steps
115166
116-
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.
167+
In this quickstart, you created a feature flag in App Configuration and used it with a console app. To learn how to dynamically update feature flags and other configuration values without restarting the application, continue to the next tutorial.
168+
117169
118170
> [!div class="nextstepaction"]
119-
> [Enable dynamic configuration](./enable-dynamic-configuration-dotnet.md)
171+
> [Enable dynamic configuration in a .NET app](./enable-dynamic-configuration-dotnet-core.md)
172+
173+
> [!div class="nextstepaction"]
174+
> [Enable dynamic configuration in a .NET Framework app](./enable-dynamic-configuration-dotnet.md)
175+

0 commit comments

Comments
 (0)