Skip to content

Commit 8f4c600

Browse files
authored
Adopt dotnet scaffold tooling (#36606)
1 parent ba05ead commit 8f4c600

2 files changed

Lines changed: 118 additions & 8 deletions

File tree

aspnetcore/blazor/tutorials/movie-database-app/part-1.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ if (!app.Environment.IsDevelopment())
304304
By default, an ASP.NET Core app doesn't provide a status code page for HTTP error status codes, such as *404 - Not Found*. When the app sets an HTTP 400-599 error status code without a body, it returns the status code and an empty response body. However, an app generated from the Blazor Web App project template calls <xref:Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute%2A> to add Status Code Pages Middleware to the request pipeline for pages that aren't found, which generates the response body by re-executing the request pipeline using the path to the Not Found error page (`/not-found`):
305305

306306
```csharp
307-
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
307+
app.UseStatusCodePagesWithReExecute("/not-found",
308+
createScopeForStatusCodePages: true);
308309
```
309310

310311
:::moniker-end

aspnetcore/blazor/tutorials/movie-database-app/part-2.md

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Build a Blazor movie database app (Part 2 - Add and scaffold a model)
3+
ai-usage: ai-assisted
34
author: guardrex
45
description: This part of the Blazor movie database app tutorial explains how to add a movie class to the app and scaffold the database and UI from the movie class.
56
monikerRange: '>= aspnetcore-8.0'
@@ -113,9 +114,21 @@ Select **Build** > **Build Solution** from the menu bar or press <kbd>F6</kbd> o
113114

114115
## Add Nuget packages and tools
115116

116-
To add the required NuGet packages and tools, execute the following .NET CLI commands in the **Terminal** (**Terminal** menu > **New Terminal**).
117+
:::moniker range=">= aspnetcore-9.0"
117118

118-
Paste all of the following commands at the prompt (`>`) of the **Terminal**. When you paste multiple commands, a warning appears stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
119+
To add the `dotnet scaffold` tool, execute the following .NET CLI command in the **Terminal** (**Terminal** menu > **New Terminal**) opened to the project's root folder:
120+
121+
```dotnetcli
122+
dotnet tool install --global Microsoft.dotnet-scaffold
123+
```
124+
125+
:::moniker-end
126+
127+
:::moniker range="< aspnetcore-9.0"
128+
129+
To add the required NuGet packages and tools, execute the following .NET CLI commands in the **Terminal** (**Terminal** menu > **New Terminal**) opened to the project's root folder.
130+
131+
Paste all of the following commands at the prompt (`>`) of the **Terminal**. When you paste multiple commands, a warning may appear stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
119132

120133
When you paste multiple commands, all of the commands execute except the last one. The last command doesn't execute until you press <kbd>Enter</kbd> on the keyboard.
121134

@@ -137,8 +150,6 @@ dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
137150
> [!NOTE]
138151
> The preceding commands are .NET CLI commands, and .NET CLI commands are executed when entered at a [PowerShell](/powershell/) prompt, which is the default command shell of the VS Code **Terminal**.
139152
140-
Save the project file.
141-
142153
The preceding commands add:
143154

144155
* [Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
@@ -148,6 +159,10 @@ The preceding commands add:
148159
* [`Microsoft.VisualStudio.Web.CodeGeneration.Design`](https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design) for scaffolding.
149160
* [`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
150161

162+
:::moniker-end
163+
164+
Save any open files.
165+
151166
In the **Command Palette** (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>), use the `.NET: Build` command to build the app.
152167

153168
Confirm that the app built successfully.
@@ -158,9 +173,21 @@ Confirm that the app built successfully.
158173

159174
## Add Nuget packages and tools
160175

176+
:::moniker range=">= aspnetcore-9.0"
177+
178+
To add the `dotnet scaffold` tool, execute the following .NET CLI command in a command shell opened to the project's root folder:
179+
180+
```dotnetcli
181+
dotnet tool install --global Microsoft.dotnet-scaffold
182+
```
183+
184+
:::moniker-end
185+
186+
:::moniker range="< aspnetcore-9.0"
187+
161188
To add the required NuGet packages and tools, execute the following .NET CLI commands in a command shell opened to the project's root folder.
162189

163-
Paste all of the following commands at the prompt (`>`) of the command shell. When you paste multiple commands, a warning appears stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
190+
Paste all of the following commands at the prompt (`>`) of the command shell. When you paste multiple commands, a warning may appear stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
164191

165192
When you paste multiple commands, all of the commands execute except the last one. The last command doesn't execute until you press <kbd>Enter</kbd> on the keyboard.
166193

@@ -176,8 +203,6 @@ dotnet add package Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdap
176203
dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
177204
```
178205

179-
Save the project file.
180-
181206
The preceding commands add:
182207

183208
* [Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
@@ -187,6 +212,10 @@ The preceding commands add:
187212
* [`Microsoft.VisualStudio.Web.CodeGeneration.Design`](https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design) for scaffolding.
188213
* [`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
189214

215+
:::moniker-end
216+
217+
Save any open files.
218+
190219
In a command shell opened to the project's root folder, execute the [`dotnet build`](/dotnet/core/tools/dotnet-build) command:
191220

192221
```dotnetcli
@@ -230,6 +259,44 @@ Complete the **Add Razor Components using Entity Framework (CRUD)** dialog:
230259

231260
In the **Terminal** (**Terminal** menu > **New Terminal**) opened to the project's root directory, execute the following command. SQLite is used as the database for users adopting VS Code tooling for this tutorial series.
232261

262+
:::moniker range=">= aspnetcore-9.0"
263+
264+
```dotnetcli
265+
dotnet scaffold
266+
```
267+
268+
When the initializing prompt appears, press <kbd>Enter</kbd> on the keyboard.
269+
270+
For the **Scaffolding Category**, use the arrow keys to select **Blazor**. Press <kbd>Enter</kbd>.
271+
272+
For the **Command Name**, use the arrow keys to select **Razor Components with EntityFrameworkCore (CRUD)**. Press <kbd>Enter</kbd>.
273+
274+
*CRUD* is an acronym for Create, Read, Update, and Delete. The scaffolder produces create, edit, delete, details, and index components for the app.
275+
276+
For the **.NET project file**, press <kbd>Enter</kbd> to accept the app's project file (`BlazorWebAppMovies.csproj`).
277+
278+
For the **Model Name**, confirm that **Movie** (`Movie` class) is selected. Press <kbd>Enter</kbd>.
279+
280+
For the **Data Context Class**, type `BlazorWebAppMoviesContext`. Press <kbd>Enter</kbd>.
281+
282+
For the **Database Provider**, use the arrow keys to select **sqlite-efcore**. Press <kbd>Enter</kbd>.
283+
284+
For **Page**, confirm that **CRUD** is selected. Press <kbd>Enter</kbd>.
285+
286+
When prompted to include prerelease packages, use the arrow keys to select **No**. Press <kbd>Enter</kbd>.
287+
288+
Executing the `dotnet scaffold` command adds the following tools and packages to the app:
289+
290+
* [Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
291+
* [`dotnet scaffold` tooling](https://devblogs.microsoft.com/dotnet/introducing-dotnet-scaffold/).
292+
* Design time tools for EF Core.
293+
* The SQLite provider with the EF Core package as a dependency.
294+
* [`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
295+
296+
:::moniker-end
297+
298+
:::moniker range="< aspnetcore-9.0"
299+
233300
```dotnetcli
234301
dotnet aspnet-codegenerator blazor CRUD -dbProvider sqlite -dc BlazorWebAppMovies.Data.BlazorWebAppMoviesContext -m Movie -outDir Components/Pages
235302
```
@@ -243,12 +310,52 @@ The following table details the ASP.NET Core code generator options used in the
243310
* `-m`: The name of the model.
244311
* `-outDir`: The output directory for the generated components. A folder is created from the model name in the output directory to hold the components (for example, `MoviePages` in this case).
245312

313+
:::moniker-end
314+
246315
:::zone-end
247316

248317
:::zone pivot="cli"
249318

250319
In a command shell opened to the project's root folder, execute the following command. SQLite is used as the database for users adopting .NET CLI tooling for this tutorial series.
251320

321+
:::moniker range=">= aspnetcore-9.0"
322+
323+
```dotnetcli
324+
dotnet scaffold
325+
```
326+
327+
When the initializing prompt appears, press <kbd>Enter</kbd> on the keyboard.
328+
329+
For the **Scaffolding Category**, use the arrow keys to select **Blazor**. Press <kbd>Enter</kbd>.
330+
331+
For the **Command Name**, use the arrow keys to select **Razor Components with EntityFrameworkCore (CRUD)**. Press <kbd>Enter</kbd>.
332+
333+
*CRUD* is an acronym for Create, Read, Update, and Delete. The scaffolder produces create, edit, delete, details, and index components for the app.
334+
335+
For the **.NET project file**, press <kbd>Enter</kbd> to accept the app's project file (`BlazorWebAppMovies.csproj`).
336+
337+
For the **Model Name**, confirm that **Movie** (`Movie` class) is selected. Press <kbd>Enter</kbd>.
338+
339+
For the **Data Context Class**, type `BlazorWebAppMoviesContext`. Press <kbd>Enter</kbd>.
340+
341+
For the **Database Provider**, use the arrow keys to select **sqlite-efcore**. Press <kbd>Enter</kbd>.
342+
343+
For **Page**, confirm that **CRUD** is selected. Press <kbd>Enter</kbd>.
344+
345+
When prompted to include prerelease packages, use the arrow keys to select **No**. Press <kbd>Enter</kbd>.
346+
347+
Executing the `dotnet scaffold` command adds the following tools and packages to the app:
348+
349+
* [Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
350+
* [`dotnet scaffold` tooling](https://devblogs.microsoft.com/dotnet/introducing-dotnet-scaffold/).
351+
* Design time tools for EF Core.
352+
* The SQLite provider with the EF Core package as a dependency.
353+
* [`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
354+
355+
:::moniker-end
356+
357+
:::moniker range="< aspnetcore-9.0"
358+
252359
```dotnetcli
253360
dotnet aspnet-codegenerator blazor CRUD -dbProvider sqlite -dc BlazorWebAppMovies.Data.BlazorWebAppMoviesContext -m Movie -outDir Components/Pages
254361
```
@@ -262,6 +369,8 @@ The following table details the ASP.NET Core code generator options used in the
262369
* `-m`: The name of the model.
263370
* `-outDir`: The output directory for the generated components. A folder is created from the model name in the output directory to hold the components (for example, `MoviePages` in this case).
264371

372+
:::moniker-end
373+
265374
:::zone-end
266375

267376
The `appsettings.json` file is updated with the connection string used to connect to a local database. In the following example, the `{CONNECTION STRING}` is the connection string automatically generated by the scaffolder:

0 commit comments

Comments
 (0)