Skip to content

Commit 9a00b9c

Browse files
authored
Merge pull request #100131 from jpconnock/ac-aspnet-qs
App Config ASP.NET Core QS update with CORE 3.x
2 parents 0c23a2c + 6599402 commit 9a00b9c

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

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

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Quickstart for Azure App Configuration with ASP.NET Core | Microsoft Docs
33
description: Quickstart for using Azure App Configuration with ASP.NET Core apps
44
services: azure-app-configuration
5-
author: yegu-ms
5+
author: jpconnock
66

77
ms.service: azure-app-configuration
88
ms.devlang: csharp
99
ms.topic: quickstart
10-
ms.date: 12/03/2019
11-
ms.author: yegu
10+
ms.date: 01/04/2020
11+
ms.author: jeconnoc
1212

1313
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
1414
---
@@ -47,18 +47,23 @@ Use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/dotn
4747

4848
1. In the new folder, run the following command to create a new ASP.NET Core MVC web app project:
4949

50-
```CLI
51-
dotnet new mvc --no-https
52-
```
50+
```dotnetcli
51+
dotnet new mvc --no-https
52+
```
5353

5454
## Add Secret Manager
5555

5656
To use Secret Manager, add a `UserSecretsId` element to your *.csproj* file.
5757

58-
- Open the *.csproj* file. Add a `UserSecretsId` element as shown here. You can use the same GUID, or you can replace this value with your own. Save the file.
58+
Open the *.csproj* file. Add a `UserSecretsId` element as shown here. You can use the same GUID, or you can replace this value with your own. Save the file.
59+
60+
> [!IMPORTANT]
61+
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
5962
60-
```xml
61-
<Project Sdk="Microsoft.NET.Sdk.Web">
63+
#### [.NET Core 2.x](#tab/core2x)
64+
65+
```xml
66+
<Project Sdk="Microsoft.NET.Sdk.Web">
6267

6368
<PropertyGroup>
6469
<TargetFramework>netcoreapp2.1</TargetFramework>
@@ -70,31 +75,45 @@ To use Secret Manager, add a `UserSecretsId` element to your *.csproj* file.
7075
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
7176
</ItemGroup>
7277

73-
</Project>
74-
```
78+
</Project>
79+
```
80+
81+
#### [.NET Core 3.x](#tab/core3x)
82+
83+
```xml
84+
<Project Sdk="Microsoft.NET.Sdk.Web">
85+
86+
<PropertyGroup>
87+
<TargetFramework>netcoreapp3.1</TargetFramework>
88+
<UserSecretsId>79a3edd0-2092-40a2-a04d-dcb46d5ca9ed</UserSecretsId>
89+
</PropertyGroup>
90+
91+
</Project>
92+
```
93+
---
7594

7695
The Secret Manager tool stores sensitive data for development work outside of your project tree. This approach helps prevent the accidental sharing of app secrets within source code. For more information on Secret Manager, please see [Safe storage of app secrets in development in ASP.NET Core](https://docs.microsoft.com/aspnet/core/security/app-secrets)
7796

7897
## Connect to an App Configuration store
7998

8099
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
81100

82-
```CLI
83-
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 2.0.0-preview-010060003-1250
101+
```dotnetcli
102+
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 3.0.0-preview-010560002-1165
84103
```
85-
2. Run the following command to restore packages for your project:
104+
1. Run the following command to restore packages for your project:
86105
87-
```CLI
88-
dotnet restore
106+
```dotnetcli
107+
dotnet restore
89108
```
90-
3. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
109+
1. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
91110
92111
This secret contains the connection string to access your App Configuration store. Replace the value in the following command with the connection string for your App Configuration store.
93112
94113
This command must be executed in the same directory as the *.csproj* file.
95114
96-
```CLI
97-
dotnet user-secrets set ConnectionStrings:AppConfig <your_connection_string>
115+
```dotnetcli
116+
dotnet user-secrets set ConnectionStrings:AppConfig <your_connection_string>
98117
```
99118
100119
> [!IMPORTANT]
@@ -104,18 +123,18 @@ The Secret Manager tool stores sensitive data for development work outside of yo
104123
105124
Access this secret using the configuration API. A colon (:) works in the configuration name with the configuration API on all supported platforms. See [Configuration by environment](https://docs.microsoft.com/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-2.0).
106125
107-
4. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
126+
1. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
108127
109128
```csharp
110129
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
111130
```
112131
113-
5. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
132+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
114133
115134
> [!IMPORTANT]
116135
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
117136
118-
### Update `CreateWebHostBuilder` for .NET Core 2.x
137+
#### [.NET Core 2.x](#tab/core2x)
119138
120139
```csharp
121140
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
@@ -128,8 +147,8 @@ The Secret Manager tool stores sensitive data for development work outside of yo
128147
.UseStartup<Startup>();
129148
```
130149
131-
### Update `CreateHostBuilder` for .NET Core 3.x
132-
150+
#### [.NET Core 3.x](#tab/core3x)
151+
133152
```csharp
134153
public static IHostBuilder CreateHostBuilder(string[] args) =>
135154
Host.CreateDefaultBuilder(args)
@@ -141,8 +160,9 @@ The Secret Manager tool stores sensitive data for development work outside of yo
141160
})
142161
.UseStartup<Startup>());
143162
```
163+
---
144164
145-
6. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
165+
1. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
146166
147167
```HTML
148168
@using Microsoft.Extensions.Configuration
@@ -161,7 +181,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
161181
<h1>@Configuration["TestApp:Settings:Message"]</h1>
162182
```
163183
164-
7. Navigate to *<app root>/Views/Shared* and open *_Layout.cshtml*. Replace its content with the following code:
184+
1. Navigate to *<app root>/Views/Shared* and open *_Layout.cshtml*. Replace its content with the following code:
165185
166186
```HTML
167187
<!DOCTYPE html>
@@ -192,17 +212,17 @@ The Secret Manager tool stores sensitive data for development work outside of yo
192212
193213
1. To build the app using the .NET Core CLI, navigate to the root directory of your application and run the following command in the command shell:
194214
195-
```CLI
196-
dotnet build
215+
```dotnetcli
216+
dotnet build
197217
```
198218
199-
2. After the build successfully completes, run the following command to run the web app locally:
219+
1. After the build successfully completes, run the following command to run the web app locally:
200220
201-
```CLI
202-
dotnet run
221+
```dotnetcli
222+
dotnet run
203223
```
204224
205-
3. If you're working on your local machine, use a browser to navigate to `http://localhost:5000`. This is the default URL for the web app hosted locally.
225+
1. If you're working on your local machine, use a browser to navigate to `http://localhost:5000`. This is the default URL for the web app hosted locally.
206226
207227
If you're working in the Azure Cloud Shell, select the *Web Preview* button followed by *Configure*.
208228

0 commit comments

Comments
 (0)