Skip to content

Commit 95b7099

Browse files
committed
Initial commit
1 parent bf606f0 commit 95b7099

File tree

1 file changed

+80
-4
lines changed

1 file changed

+80
-4
lines changed

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

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ ms.service: azure-app-configuration
77
ms.devlang: csharp
88
ms.custom: devx-track-csharp, mode-other, devx-track-dotnet
99
ms.topic: quickstart
10-
ms.date: 05/24/2024
10+
ms.date: 02/04/2025
1111
ms.author: malev
1212
#Customer intent: As a .NET Framework developer, I want to manage all my app settings in one place.
1313
---
1414
# Quickstart: Create a .NET Framework app with Azure App Configuration
1515

1616
There are two ways to incorporate Azure App Configuration into a .NET Framework-based app.
1717

18-
- 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 will walk you through this option.
19-
- 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 are willing to make code changes, see tutorials on how you can implement dynamic configuration updates in a [.NET Framework console app](./enable-dynamic-configuration-dotnet.md) or an [ASP.NET web app](./enable-dynamic-configuration-aspnet-netfx.md).
18+
- 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.
19+
- 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](./enable-dynamic-configuration-dotnet.md) or an [ASP.NET web app](./enable-dynamic-configuration-aspnet-netfx.md).
2020

2121
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.
2222

@@ -45,6 +45,53 @@ Add the following key-value to the App Configuration store and leave **Label** a
4545

4646
## Connect to an App Configuration store
4747

48+
Connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
49+
50+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
51+
52+
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the following NuGet packages to your project.
53+
54+
- *Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration* version 1.0.0 or later
55+
- *Microsoft.Configuration.ConfigurationBuilders.Environment* version 2.0.0 or later
56+
- *System.Configuration.ConfigurationManager* version 4.6.0 or later
57+
- * Azure.Identity* version 1.13.0 or later
58+
59+
1. Update the *App.config* file of your project as follows. You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) 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.
60+
61+
```xml
62+
<configSections>
63+
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
64+
</configSections>
65+
66+
<configBuilders>
67+
<builders>
68+
<add name="MyConfigStore" mode="Greedy" connectionString="${ConnectionString}" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />
69+
<add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
70+
</builders>
71+
</configBuilders>
72+
73+
<appSettings configBuilders="Environment,MyConfigStore">
74+
<add key="AppName" value="Console App Demo" />
75+
<add key="ConnectionString" value ="Set via an environment variable - for example, dev, test, staging, or production connection string." />
76+
</appSettings>
77+
```
78+
79+
The connection string of your App Configuration store is read from the environment variable `ConnectionString`. Add the `Environment` configuration builder before the `MyConfigStore` in the `configBuilders` property of the `appSettings` section.
80+
81+
1. Open *Program.cs*, and update the `Main` method to use App Configuration by calling `ConfigurationManager`.
82+
83+
```csharp
84+
static void Main(string[] args)
85+
{
86+
string message = System.Configuration.ConfigurationManager.AppSettings["TestApp:Settings:Message"];
87+
88+
Console.WriteLine(message);
89+
Console.ReadKey();
90+
}
91+
```
92+
93+
### [Connection string](#tab/connection-string)
94+
4895
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the following NuGet packages to your project.
4996

5097
- *Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration* version 1.0.0 or later
@@ -85,9 +132,37 @@ Add the following key-value to the App Configuration store and leave **Label** a
85132
}
86133
```
87134

135+
---
136+
88137
## Build and run the app
89138

90-
1. Set an environment variable named **ConnectionString** to the read-only key connection string obtained during your App Configuration store creation.
139+
1. Set an environment variable.
140+
141+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
142+
143+
Set the environment variable named **APP_CONFIGURATION_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
144+
145+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
146+
147+
```cmd
148+
setx APP_CONFIGURATION_ENDPOINT "<endpoint-of-your-app-configuration-store>"
149+
```
150+
151+
If you use PowerShell, run the following command:
152+
153+
```powershell
154+
$Env:APP_CONFIGURATION_ENDPOINT = "<endpoint-of-your-app-configuration-store>"
155+
```
156+
157+
If you use macOS or Linux, run the following command:
158+
159+
```bash
160+
export APP_CONFIGURATION_ENDPOINT='<endpoint-of-your-app-configuration-store>'
161+
```
162+
163+
### [Connection string](#tab/connection-string)
164+
165+
Set an environment variable named **ConnectionString** to the read-only key connection string obtained during your App Configuration store creation.
91166

92167
If you use the Windows command prompt, run the following command:
93168

@@ -100,6 +175,7 @@ Add the following key-value to the App Configuration store and leave **Label** a
100175
```powershell
101176
$Env:ConnectionString = "<connection-string-of-your-app-configuration-store>"
102177
```
178+
---
103179

104180
1. Restart Visual Studio to allow the change to take effect.
105181

0 commit comments

Comments
 (0)