Overview
dotnet scaffold
is an interactive command line tool to scaffold ASP.NET Core projects.
Installation
dotnet tool install --global Microsoft.dotnet-scaffold
Usage Example - General
dotnet scaffold
follows a general pattern for all project types:
dotnet scaffold
to start the interactive tool- Select a scaffolding category (project type) (like Razor Pages)
- Select a scaffolder (like Razor Page - Empty)
- Select the .NET project file (like MyWebApp.csproj)
The command scaffolds the project.
Usage Example - Entity Framework Scaffolders
To scaffold EF, you first need a model class. Then, invoke dotnet scaffold
:
- Select scaffolding category Razor Pages
- Select scaffolder Razor Pages with Entity Framework (CRUD)
- Select the .NET project file
- Select the model class file
- Enter the name of the database context (suffix it with
DbContext
) - Select the database provider (like sqlite-efcore)
- Select the operations to scaffold (like CRUD or Create)
At this stage:
- the project file is updated with package references for Entity Framework
Program.cs
is updated to initialize the database connectionappsettings.json
is updated with connection information*DbContext.cs
has been created and added to the project root- Razor Pages for CRUD operations has been added to the
Pages
folder
- Migrate the database:
dotnet ef migrations add initialMigration
- Update the database:
dotnet ef database update