aspnetcore/fundamentals/tools/dotnet-aspnet-codegenerator.md
aspnet-codegenerator)The dotnet aspnet-codegenerator command runs the ASP.NET Core scaffolding engine. Running the dotnet aspnet-codegenerator command is required to scaffold from the command line or when using Visual Studio Code. The command isn't required to use scaffolding with Visual Studio, which includes the scaffolding engine by default.
Install the .NET SDK.
dotnet aspnet-codegenerator is a global tool that must be installed. The following command installs the latest stable version of the ASP.NET Core code generator tool:
dotnet tool install -g dotnet-aspnet-codegenerator
If the tool is already installed, the following command updates the tool to the latest stable version available from the installed .NET SDKs:
dotnet tool update -g dotnet-aspnet-codegenerator
It may be necessary to uninstall the ASP.NET Core code generator tool to resolve problems. For example, if you installed a preview version of the tool, uninstall it before installing the released version.
The following commands uninstall the ASP.NET Core code generator tool and install the latest stable version:
dotnet tool uninstall -g dotnet-aspnet-codegenerator
dotnet tool install -g dotnet-aspnet-codegenerator
dotnet aspnet-codegenerator [arguments] [-b|--build-base-path] [-c|--configuration] [-n|--nuget-package-dir] [--no-build] [-p|--project] [-tfm|--target-framework]
dotnet aspnet-codegenerator [-h|--help]
The dotnet aspnet-codegenerator global command runs the ASP.NET Core code generator and scaffolding engine.
generator
The code generator to run. The available generators are shown in the following table.
:::moniker range=">= aspnetcore-8.0"
| Generator | Operation |
|---|---|
area | Scaffolds an area. |
blazor | Scaffolds Blazor create, read, update, delete, and list pages. |
blazor-identity | Generates Blazor Identity files. |
controller | Scaffolds a controller. |
identity | Scaffolds Identity. |
minimalapi | Generates an endpoints file (with CRUD API endpoints) given a model and optional database context. |
razorpage | Scaffolds Razor Pages. |
view | Scaffolds a view. |
:::moniker-end
:::moniker range="< aspnetcore-8.0"
| Generator | Operation |
|---|---|
area | Scaffolds an area. |
controller | Scaffolds a controller. |
identity | Scaffolds Identity. |
minimalapi | Generates an endpoints file (with CRUD API endpoints) given a model and optional database context. |
razorpage | Scaffolds Razor Pages. |
view | Scaffolds a view. |
:::moniker-end
-b|--build-base-path
The build base path.
-c|--configuration {Debug|Release}
Defines the build configuration. The default value is Debug.
-h|--help
Prints out a short help for the command.
-n|--nuget-package-dir
Specifies the NuGet package directory.
--no-build
Doesn't build the project before running. Passing --no-build also implicitly sets the --no-restore flag.
-p|--project <PATH>
Specifies the path of the project file to run (folder name or full path). If not specified, the tool defaults to the current directory.
-tfm|--target-framework
The target framework to use.
The following sections detail the options available for the supported generators:
:::moniker range=">= aspnetcore-8.0"
area)controller)blazor)blazor-identity)identity)minimalapi)razorpage)view):::moniker-end
:::moniker range="< aspnetcore-8.0"
area)controller)identity)minimalapi)razorpage)view):::moniker-end
Usage: dotnet aspnet-codegenerator area {AREA NAME}
The {AREA NAME} placeholder is the name of the area to generate.
The preceding command generates the following folders:
Areas
{AREA NAME}
ControllersDataModelsViewsUse the -h|--help option for help:
dotnet aspnet-codegenerator area -h
:::moniker range=">= aspnetcore-8.0"
Razor components can be individually scaffolded for Blazor apps by specifying the name of the template to use. The supported templates are:
EmptyCreateEditDeleteDetailsListCRUD: CRUD is an acronym for Create, Read, Update, and Delete. The CRUD template produces Create, Edit, Delete, Details, and Index (List) components for the app.The options for the blazor generator are shown in the following table.
| Option | Description |
|---|---|
| `-dbProvider | --databaseProvider` |
| `-dc | --dataContext` |
| `-m | --model` |
| `-ns | --namespaceName` |
| `--relativeFolderPath | -outDir` |
The following example:
Edit template to generate an Edit component (Edit.razor) in the Components/Pages/MoviePages folder of the app. If the MoviePages folder doesn't exist, the tool creates the folder automatically.BlazorWebAppMovies.Data.BlazorWebAppMoviesContext for the database context.Movie model.dotnet aspnet-codegenerator blazor Edit -dbProvider sqlite -dc BlazorWebAppMovies.Data.BlazorWebAppMoviesContext -m Movie -outDir Components/Pages
Use the -h|--help option for help:
dotnet aspnet-codegenerator blazor -h
For an example that uses the blazor generator, see xref:blazor/tutorials/movie-database-app/index.
For more information, see xref:blazor/components/quickgrid#quickgrid-scaffolder.
Scaffold Identity Razor components into a Blazor app with the blazor-identity generator.
The options for the blazor-identity template are shown in the following table.
| Option | Description |
|---|---|
| `-dbProvider | --databaseProvider` |
| `-dc | --dataContext` |
| `-f | --force` |
| `-fi | --files` |
| `-lf | --listFiles` |
| `-rn | --rootNamespace` |
| `-u | --userClass` |
Use the -h|--help option for help:
dotnet aspnet-codegenerator blazor-identity -h
:::moniker-end
General options are shown in the following table.
The options unique to controller are shown in the following table.
| Option | Description |
|---|---|
| `-actions | --readWriteActions` |
| `-api | --restWithNoViews` |
| `-async | --useAsyncActions` |
| `-name | --controllerName` |
| `-namespace | --controllerNamespace` |
| `-nv | --noViews` |
Use the -h|--help option for help:
dotnet aspnet-codegenerator controller -h
For an example that uses the controller generator, see xref:tutorials/first-mvc-app/adding-model.
For more information, see xref:security/authentication/scaffold-identity.
Scaffold a Minimal API backend with the minimalapi template.
The options for minimalapi are shown in the following table.
| Option | Description |
|---|---|
| `-dbProvider | --databaseProvider` |
| `-dc | --dataContext` |
| `-e | --endpoints` |
| `-m | --model` |
| `-namespace | --endpointsNamespace` |
| `-o | --open` |
| `-outDir | --relativeFolderPath` |
| `-sqlite | --useSqlite` |
The following example:
SpeakersEndpoints with API endpoints that map to database operations using the ApplicationDbContext database context class and the BackEnd.Models.Speaker model.app.MapSpeakerEndpoints(); to the Program file (Program.cs) to register the endpoints class.dotnet aspnet-codegenerator minimalapi -dc ApplicationDbContext -e SpeakerEndpoints -m BackEnd.Models.Speaker -o
Use the -h|--help option for help:
dotnet aspnet-codegenerator minimalapi -h
Razor Pages can be individually scaffolded by specifying the name of the new page and the template to use. The supported templates are:
EmptyCreateEditDeleteDetailsListTypically, the template and generated file name isn't specified, which creates the following templates:
CreateEditDeleteDetailsListGeneral options are shown in the following table.
The options unique to razorpage are shown in the following table.
| Option | Description |
|---|---|
| `-namespace | --namespaceName` |
| `-npm | --noPageModel` |
| `-partial | --partialView` |
The following example uses the Edit template to generate CustomEditPage.cshtml and CustomEditPage.cshtml.cs in the Pages/Movies folder:
dotnet aspnet-codegenerator razorpage CustomEditPage Edit -dc RazorPagesMovieContext -m Movie -outDir Pages/Movies
Use the -h|--help option for help:
dotnet aspnet-codegenerator razorpage -h
For an example that uses the razorpage generator, see xref:tutorials/razor-pages/model.
Views can be individually scaffolded by specifying the name of the view and the template. The supported templates are:
EmptyCreateEditDeleteDetailsListGeneral options are shown in the following table.
The options unique to view are shown in the following table.
| Option | Description |
|---|---|
| `-namespace | --controllerNamespace` |
| `-partial | --partialView` |
The following example uses the Edit template to generate CustomEditView.cshtml in the Views/Movies folder:
dotnet aspnet-codegenerator view CustomEditView Edit -dc MovieContext -m Movie -outDir Views/Movies
Use the -h|--help option for help:
dotnet aspnet-codegenerator view -h