Skip to content

Commit 413783c

Browse files
authored
Merge pull request #91426 from jpconnock/app-config-update-qs
Updating App Config QS with new .NET method
2 parents c56e76f + e5c47d4 commit 413783c

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.devlang: csharp
1313
ms.topic: quickstart
1414
ms.tgt_pltfrm: ASP.NET Core
1515
ms.workload: tbd
16-
ms.date: 02/24/2019
16+
ms.date: 10/11/2019
1717
ms.author: yegu
1818

1919
#Customer intent: As an ASP.NET Core developer, I want to manage all my app settings in one place.
@@ -50,7 +50,9 @@ You use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/
5050

5151
2. In the new folder, run the following command to create a new ASP.NET Core MVC web app project:
5252

53+
```CLI
5354
dotnet new mvc --no-https
55+
```
5456
5557
## Add Secret Manager
5658
@@ -80,19 +82,23 @@ The Secret Manager tool stores sensitive data for development work outside of yo
8082
8183
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
8284
85+
```CLI
8386
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 2.0.0-preview-010060003-1250
84-
87+
```
8588
2. Run the following command to restore packages for your project:
8689
90+
```CLI
8791
dotnet restore
88-
92+
```
8993
3. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
9094
9195
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.
9296
9397
This command must be executed in the same directory as the *.csproj* file.
9498
99+
```CLI
95100
dotnet user-secrets set ConnectionStrings:AppConfig <your_connection_string>
101+
```
96102
97103
> [!IMPORTANT]
98104
> Some shells will truncate the connection string unless it is enclosed in quotes. Ensure that the output of the `dotnet user-secrets` command shows the entire connection string. If it doesn't, rerun the command, enclosing the connection string in quotes.
@@ -108,6 +114,11 @@ The Secret Manager tool stores sensitive data for development work outside of yo
108114
```
109115
110116
5. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
117+
118+
> [!IMPORTANT]
119+
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
120+
121+
### Update `CreateWebHostBuilder` for .NET Core 2.x
111122
112123
```csharp
113124
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
@@ -120,9 +131,23 @@ The Secret Manager tool stores sensitive data for development work outside of yo
120131
.UseStartup<Startup>();
121132
```
122133
134+
### Update `CreateHostBuilder` for .NET Core 3.x
135+
136+
```csharp
137+
public static IHostBuilder CreateHostBuilder(string[] args) =>
138+
Host.CreateDefaultBuilder(args)
139+
.ConfigureWebHostDefaults(webBuilder =>
140+
webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
141+
{
142+
var settings = config.Build();
143+
config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);
144+
})
145+
.UseStartup<Startup>());
146+
```
147+
123148
6. Open *Index.cshtml* in the Views > Home directory, and replace its content with the following code:
124149
125-
```html
150+
```HTML
126151
@using Microsoft.Extensions.Configuration
127152
@inject IConfiguration Configuration
128153
@@ -141,7 +166,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
141166
142167
7. Open *_Layout.cshtml* in the Views > Shared directory, and replace its content with the following code:
143168
144-
```html
169+
```HTML
145170
<!DOCTYPE html>
146171
<html>
147172
<head>
@@ -170,11 +195,15 @@ The Secret Manager tool stores sensitive data for development work outside of yo
170195
171196
1. To build the app by using the .NET Core CLI, run the following command in the command shell:
172197
173-
dotnet build
198+
```CLI
199+
dotnet build
200+
```
174201
175202
2. After the build successfully completes, run the following command to run the web app locally:
176203
204+
```CLI
177205
dotnet run
206+
```
178207
179208
3. Open a browser window, and go to `http://localhost:5000`, which is the default URL for the web app hosted locally.
180209

0 commit comments

Comments
 (0)