2019-07-04 05:08:35 +08:00
---
2021-05-26 07:18:47 +08:00
title: dotnet-aspnet-codegenerator command
2019-07-04 05:08:35 +08:00
author: rick-anderson
2021-05-26 07:18:47 +08:00
description: The dotnet-aspnet-codegenerator command scaffolds ASP.NET Core projects.
2019-07-06 04:48:25 +08:00
monikerRange: '>= aspnetcore-2.1'
2019-07-04 05:08:35 +08:00
ms.author: riande
2020-11-19 09:07:10 +08:00
ms.date: 11/16/2020
2021-05-09 04:12:34 +08:00
no-loc: [Home, Privacy, Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR]
2019-07-04 05:08:35 +08:00
uid: fundamentals/tools/dotnet-aspnet-codegenerator
---
2021-05-26 07:18:47 +08:00
# dotnet-aspnet-codegenerator
2019-07-04 05:08:35 +08:00
By [Rick Anderson ](https://twitter.com/RickAndMSFT )
2021-05-26 07:18:47 +08:00
`dotnet-aspnet-codegenerator` - Runs the ASP.NET Core scaffolding engine. `dotnet-aspnet-codegenerator` is only required to scaffold from the command line, it's not needed to use scaffolding with Visual Studio.
2019-07-04 05:08:35 +08:00
2020-11-19 09:07:10 +08:00
## Install and update aspnet-codegenerator
2019-07-04 05:08:35 +08:00
2020-11-19 09:07:10 +08:00
Install the [.NET SDK ](https://dotnet.microsoft.com/download ).
2019-07-04 05:08:35 +08:00
2019-07-06 04:48:25 +08:00
`dotnet-aspnet-codegenerator` is a [global tool ](/dotnet/core/tools/global-tools ) that must be installed. The following command installs the latest stable version of the `dotnet-aspnet-codegenerator` tool:
2019-07-04 05:08:35 +08:00
2019-09-18 05:01:04 +08:00
```dotnetcli
2019-07-06 04:33:46 +08:00
dotnet tool install -g dotnet-aspnet-codegenerator
2019-07-04 05:08:35 +08:00
```
2019-07-06 04:48:25 +08:00
The following command updates `dotnet-aspnet-codegenerator` to the latest stable version available from the installed .NET Core SDKs:
2019-07-04 05:08:35 +08:00
2019-09-18 05:01:04 +08:00
```dotnetcli
2019-07-06 04:33:46 +08:00
dotnet tool update -g dotnet-aspnet-codegenerator
2019-07-04 05:08:35 +08:00
```
2020-11-19 09:07:10 +08:00
## Uninstall aspnet-codegenerator
It may be necessary to uninstall the `aspnet-codegenerator` to resolve problems. For example, if you installed a preview version of `aspnet-codegenerator` , uninstall it before installing the released version.
The following commands uninstall the `dotnet-aspnet-codegenerator` tool and installs the latest stable version:
```dotnetcli
dotnet tool uninstall -g dotnet-aspnet-codegenerator
dotnet tool install -g dotnet-aspnet-codegenerator
```
2019-07-04 05:08:35 +08:00
## Synopsis
```
2021-05-26 07:18:47 +08:00
dotnet-aspnet-codegenerator [arguments] [-p|--project] [-n|--nuget-package-dir] [-c|--configuration] [-tfm|--target-framework] [-b|--build-base-path] [--no-build]
dotnet-aspnet-codegenerator [-h|--help]
2019-07-04 05:08:35 +08:00
```
## Description
2021-05-26 07:18:47 +08:00
The `dotnet-aspnet-codegenerator` global command runs the ASP.NET Core code generator and scaffolding engine.
2019-07-04 05:08:35 +08:00
## Arguments
`generator`
The code generator to run. The following generators are available:
2020-07-30 10:00:50 +08:00
| Generator | Operation |
| ---------- | -------------------------------------------------------------------- |
| area | [Scaffolds an Area ](xref:mvc/controllers/areas ) |
| controller | [Scaffolds a controller ](xref:tutorials/first-mvc-app/adding-model ) |
| identity | [Scaffolds Identity ](xref:security/authentication/scaffold-identity ) |
| razorpage | [Scaffolds Razor Pages ](xref:tutorials/razor-pages/model ) |
| view | [Scaffolds a view ](xref:mvc/views/overview ) |
2019-07-04 05:08:35 +08:00
## Options
`-n|--nuget-package-dir`
Specifies the NuGet package directory.
`-c|--configuration {Debug|Release}`
Defines the build configuration. The default value is `Debug` .
`-tfm|--target-framework`
Target [Framework ](/dotnet/standard/frameworks ) to use. For example, `net46` .
`-b|--build-base-path`
The build base path.
`-h|--help`
Prints out a short help for the command.
`--no-build`
Doesn't build the project before running. It 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, it defaults to the current directory.
## Generator options
The following sections detail the options available for the supported generators:
* Area
* Controller
* Identity
* Razorpage
* View
< a name = "area" > < / a >
### Area options
This tool is intended for ASP.NET Core web projects with controllers and views. It's not intended for Razor Pages apps.
2021-05-26 07:18:47 +08:00
Usage: `dotnet-aspnet-codegenerator area AreaNameToGenerate`
2019-07-04 05:08:35 +08:00
The preceding command generates the following folders:
* *Areas*
* *AreaNameToGenerate*
* *Controllers*
* *Data*
* *Models*
* *Views*
< a name = "ctl" > < / a >
### Controller options
2021-05-13 02:03:51 +08:00
The following table lists options for `aspnet-codegenerator` `razorpage` , `controller` and `view` :
2019-07-04 05:08:35 +08:00
[!INCLUDE [aspnet-codegenerator-args-md.md ](~/includes/aspnet-codegenerator-args-md.md )]
The following table lists options unique to `aspnet-codegenerator controller` :
2020-07-30 10:00:50 +08:00
| Option | Description |
| ------------------------------ | --------------------------------------------------------------------------------------------------------- |
| --controllerName or -name | Name of the controller. |
| --useAsyncActions or -async | Generate async controller actions. |
| --noViews or -nv | Generate **no** views. |
| --restWithNoViews or -api | Generate a Controller with REST style API. `noViews` is assumed and any view related options are ignored. |
| --readWriteActions or -actions | Generate controller with read/write actions without a model. |
2019-07-04 05:08:35 +08:00
Use the `-h` switch for help on the `aspnet-codegenerator controller` command:
2019-09-18 05:01:04 +08:00
```dotnetcli
2021-05-26 07:18:47 +08:00
dotnet-aspnet-codegenerator controller -h
2019-07-04 05:08:35 +08:00
```
2021-05-26 07:18:47 +08:00
See [Scaffold the movie model ](xref:tutorials/first-mvc-app/adding-model ) for an example of `dotnet-aspnet-codegenerator controller` .
2019-07-04 05:08:35 +08:00
### Razorpage
< a name = "rp" > < / a >
Razor Pages can be individually scaffolded by specifying the name of the new page and the template to use. The supported templates are:
* `Empty`
* `Create`
* `Edit`
* `Delete`
* `Details`
* `List`
For example, the following command uses the Edit template to generate *MyEdit.cshtml* and *MyEdit.cshtml.cs* :
2019-09-18 05:01:04 +08:00
```dotnetcli
2021-05-26 07:18:47 +08:00
dotnet-aspnet-codegenerator razorpage MyEdit Edit -m Movie -dc RazorPagesMovieContext -outDir Pages/Movies
2019-07-04 05:08:35 +08:00
```
Typically, the template and generated file name is not specified, and the following templates are created:
* `Create`
* `Edit`
* `Delete`
* `Details`
* `List`
2021-05-13 02:03:51 +08:00
The following table lists options for `aspnet-codegenerator` `razorpage` , `controller` and `view` :
2019-07-04 05:08:35 +08:00
[!INCLUDE [aspnet-codegenerator-args-md.md ](~/includes/aspnet-codegenerator-args-md.md )]
The following table lists options unique to `aspnet-codegenerator razorpage` :
2020-07-30 10:00:50 +08:00
| Option | Description |
| ----------------------------- | ------------------------------------------------------------------------------------- |
| --namespaceName or -namespace | The name of the namespace to use for the generated PageModel |
| --partialView or -partial | Generate a partial view. Layout options -l and -udl are ignored if this is specified. |
| --noPageModel or -npm | Switch to not generate a PageModel class for Empty template |
2019-07-04 05:08:35 +08:00
Use the `-h` switch for help on the `aspnet-codegenerator razorpage` command:
2019-09-18 05:01:04 +08:00
```dotnetcli
2021-05-26 07:18:47 +08:00
dotnet-aspnet-codegenerator razorpage -h
2019-07-04 05:08:35 +08:00
```
2021-05-26 07:18:47 +08:00
See [Scaffold the movie model ](xref:tutorials/razor-pages/model ) for an example of `dotnet-aspnet-codegenerator razorpage` .
2019-07-04 05:08:35 +08:00
2021-05-13 02:03:51 +08:00
### View
Views can be individually scaffolded by specifying the name of the view and the template to use. The supported templates are:
* `Empty`
* `Create`
* `Edit`
* `Delete`
* `Details`
* `List`
For example, the following command uses the Edit template to generate *MyEdit.cshtml* :
```dotnetcli
2021-05-26 07:18:47 +08:00
dotnet-aspnet-codegenerator view MyEdit Edit -m Movie -dc MovieContext -outDir Views/Movies
2021-05-13 02:03:51 +08:00
```
The following table lists options for `aspnet-codegenerator` `razorpage` , `controller` and `view` :
[!INCLUDE [aspnet-codegenerator-args-md.md ](~/includes/aspnet-codegenerator-args-md.md )]
The following table lists options unique to `aspnet-codegenerator view` :
| Option | Description |
| ----------------------------- | ------------------------------------------------------------------------------------- |
| --controllerNamespace or -namespace | Specify the name of the namespace to use for the generated controller |
| --partialView or -partial | Generate a partial view, other layout options (-l and -udl) are ignored if this is specified |
Use the `-h` switch for help on the `aspnet-codegenerator view` command:
```dotnetcli
2021-05-26 07:18:47 +08:00
dotnet-aspnet-codegenerator view -h
2021-05-13 02:03:51 +08:00
```
2019-07-04 05:08:35 +08:00
### Identity
2020-07-30 10:00:50 +08:00
See [Scaffold Identity ](xref:security/authentication/scaffold-identity )