Notikumi
Power BI DataViz pasaules čempionāts
14. febr. 16 - 31. marts 16
Ar 4 iespējām piedalīties, jūs varētu laimēt konferences paketi un iekļūt LIVE Grand Finale Lasvegasā
Uzzināt vairākŠī pārlūkprogramma vairs netiek atbalstīta.
Jauniniet uz Microsoft Edge, lai izmantotu jaunāko līdzekļu, drošības atjauninājumu un tehniskā atbalsta sniegtās priekšrocības.
aspnet-codegenerator
)Piezīme
This isn't the latest version of this article. For the current release, see the .NET 9 version of this article.
Brīdinājums
This version of ASP.NET Core is no longer supported. For more information, see the .NET and .NET Core Support Policy. For the current release, see the .NET 9 version of this article.
Svarīgi
This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
For the current release, see the .NET 9 version of this article.
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
Piezīme
By default the architecture of the .NET binaries to install represents the currently running OS architecture. To specify a different OS architecture, see dotnet tool install, --arch option. For more information, see GitHub issue dotnet/AspNetCore.Docs #29262.
If the tool is already installed, the following command updates the tool to the latest stable version available from the installed .NET Core 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.
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. |
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. |
-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:
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}
Controllers
Data
Models
Views
Use the -h|--help
option for help:
dotnet aspnet-codegenerator area -h
Razor components can be individually scaffolded for Blazor apps by specifying the name of the template to use. The supported templates are:
Empty
Create
Edit
Delete
Details
List
CRUD
: 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 |
Database provider to use. Options include sqlserver (default), sqlite , cosmos , or postgres . |
-dc|--dataContext |
Database context class to use. |
-m|--model |
Model class to use. |
-ns|--namespaceName |
Specify the name of the namespace to use for the generated Endpoints file. |
--relativeFolderPath|-outDir |
Relative output folder path. If not specified, files are generated in the project folder. |
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 Build a Blazor movie database app (Overview).
For more information, see ASP.NET Core Blazor `QuickGrid` component.
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 |
Database provider to use. Options include sqlserver (default) and sqlite . |
-dc|--dataContext |
Database context class to use. |
-f|--force |
Use this option to overwrite existing files. |
-fi|--files |
List of semicolon separated files to scaffold. Use the -lf|--listFiles option to see the available options. |
-lf|--listFiles |
Lists the files that can be scaffolded by using the -fi|--files option. |
-rn|--rootNamespace |
Root namespace to use for generating Identity code. |
-u|--userClass |
Name of the user class to generate. |
Use the -h|--help
option for help:
dotnet aspnet-codegenerator blazor-identity -h
General options are shown in the following table.
Option | Description |
---|---|
-b|--bootstrapVersion |
Specifies the bootstrap version and creates a wwwroot folder for the Bootstrap assets if the folder isn't present. |
-dbProvider|--databaseProvider |
Database provider to use. Options include sqlserver (default), sqlite , cosmos , postgres . |
-dc|--dataContext |
The database context class to use or the name of the class to generate. |
-f|--force |
Overwrite existing files. |
-l|--layout |
Custom layout page to use. |
-m|--model |
Model class to use. |
-outDir|--relativeFolderPath |
Relative output folder path. If not specified, files are generated in the project folder. |
-scripts|--referenceScriptLibraries |
Reference script libraries in the generated views. Adds _ValidationScriptsPartial to Edit and Create pages. |
-sqlite|--useSqlite |
Flag to specify if the database context should use SQLite instead of SQL Server. |
-udl|--useDefaultLayout |
Use the default layout for the views. |
The options unique to controller
are shown in the following table.
Option | Description |
---|---|
-actions|--readWriteActions |
Generate controller with read/write actions without a model. |
-api|--restWithNoViews |
Generate a controller with REST style API. noViews is assumed and any view related options are ignored. |
-async|--useAsyncActions |
Generate asynchronous controller actions. |
-name|--controllerName |
Name of the controller. |
-namespace|--controllerNamespace |
Specify the name of the namespace to use for the generated controller. |
-nv|--noViews |
Generate no views. |
Use the -h|--help
option for help:
dotnet aspnet-codegenerator controller -h
For an example that uses the controller
generator, see Part 4, add a model to an ASP.NET Core MVC app.
For more information, see Scaffold Identity in ASP.NET Core projects.
Scaffold a Minimal API backend with the minimalapi
template.
The options for minimalapi
are shown in the following table.
Option | Description |
---|---|
-dbProvider|--databaseProvider |
Database provider to use. Options include sqlserver (default), sqlite , cosmos , or postgres . |
-dc|--dataContext |
Database context class to use. |
-e|--endpoints |
Endpoints class to use (not the file name). |
-m|--model |
Model class to use. |
-namespace|--endpointsNamespace |
Specify the name of the namespace to use for the generated endpoints file. |
-o|--open |
Use this option to enable OpenAPI. |
-outDir|--relativeFolderPath |
Relative output folder path. If not specified, files are generated in the project folder. |
-sqlite|--useSqlite |
Flag to specify if the database context should use SQLite instead of SQL Server. |
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:
Empty
Create
Edit
Delete
Details
List
Typically, the template and generated file name isn't specified, which creates the following templates:
Create
Edit
Delete
Details
List
General options are shown in the following table.
Option | Description |
---|---|
-b|--bootstrapVersion |
Specifies the bootstrap version and creates a wwwroot folder for the Bootstrap assets if the folder isn't present. |
-dbProvider|--databaseProvider |
Database provider to use. Options include sqlserver (default), sqlite , cosmos , postgres . |
-dc|--dataContext |
The database context class to use or the name of the class to generate. |
-f|--force |
Overwrite existing files. |
-l|--layout |
Custom layout page to use. |
-m|--model |
Model class to use. |
-outDir|--relativeFolderPath |
Relative output folder path. If not specified, files are generated in the project folder. |
-scripts|--referenceScriptLibraries |
Reference script libraries in the generated views. Adds _ValidationScriptsPartial to Edit and Create pages. |
-sqlite|--useSqlite |
Flag to specify if the database context should use SQLite instead of SQL Server. |
-udl|--useDefaultLayout |
Use the default layout for the views. |
The options unique to razorpage
are shown in the following table.
Option | Description |
---|---|
-namespace|--namespaceName |
The name of the namespace to use for the generated PageModel class. |
-npm|--noPageModel |
Don't generate a PageModel class for the Empty template. |
-partial|--partialView |
Generate a partial view. Layout options -l and -udl are ignored if this is specified. |
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 Part 2, add a model.
Views can be individually scaffolded by specifying the name of the view and the template. The supported templates are:
Empty
Create
Edit
Delete
Details
List
General options are shown in the following table.
Option | Description |
---|---|
-b|--bootstrapVersion |
Specifies the bootstrap version and creates a wwwroot folder for the Bootstrap assets if the folder isn't present. |
-dbProvider|--databaseProvider |
Database provider to use. Options include sqlserver (default), sqlite , cosmos , postgres . |
-dc|--dataContext |
The database context class to use or the name of the class to generate. |
-f|--force |
Overwrite existing files. |
-l|--layout |
Custom layout page to use. |
-m|--model |
Model class to use. |
-outDir|--relativeFolderPath |
Relative output folder path. If not specified, files are generated in the project folder. |
-scripts|--referenceScriptLibraries |
Reference script libraries in the generated views. Adds _ValidationScriptsPartial to Edit and Create pages. |
-sqlite|--useSqlite |
Flag to specify if the database context should use SQLite instead of SQL Server. |
-udl|--useDefaultLayout |
Use the default layout for the views. |
The options unique to view
are shown in the following table.
Option | Description |
---|---|
-namespace|--controllerNamespace |
Specify the name of the namespace to use for the generated controller. |
-partial|--partialView |
Generate a partial view. Other layout options (-l and -udl ) are ignored if this is specified. |
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
ASP.NET Core atsauksmes
ASP.NET Core ir atklātā pirmkoda projekts. Atlasiet saiti, lai sniegtu atsauksmes:
Notikumi
Power BI DataViz pasaules čempionāts
14. febr. 16 - 31. marts 16
Ar 4 iespējām piedalīties, jūs varētu laimēt konferences paketi un iekļūt LIVE Grand Finale Lasvegasā
Uzzināt vairākApmācība
Modulis
Create a .NET Aspire project - Training
Learn how to create cloud-native applications from scratch or add orchestration to an existing app by using the .NET Aspire stack in .NET 8.