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 scaffoldto 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.csis updated to initialize the database connectionappsettings.jsonis updated with connection information*DbContext.cshas been created and added to the project root- Razor Pages for CRUD operations has been added to the
Pagesfolder
- Migrate the database:
dotnet ef migrations add initialMigration - Update the database:
dotnet ef database update