Is it possible to scaffold my controller using the .NET CLI?

version for package `` could not be resolved.
dotnet aspnet-codegenerator not found
mvc scaffolding
microsoft visualstudio web codegeneration design 3.1 0
dotnet cli
packagereference include microsoft visualstudio web codegeneration design version 3.1 1

I'm following the ASP.NET Core tutorials at I'm up to the Scaffolding a Controller section and I'm trying to create a controller from my model/DB context. However, when I follow the instructions as described in the guide, I receive this error:

I tried restoring the NuGet packages and creating a new project, but I'm still getting the same error. Is there a way to scaffold the controller using the .NET CLI? I've never seen one before, so I don't know how to write one up myself.


edit: I just tried @Prafull8495's answer and modified my project file as he instructed. The above error is no longer popping up, but now I'm hitting something else:

Scaffolding ASP.NET Core API Controllers, Scaffolding ASP.NET Quickly create API controllers to jump start your project NET Core with a Web API backend and Vue.js front-end. I set out to look for a CLI alternative to creating new API controllers in Visual Studio. .NET Core CLI; From Solution Explorer, right-click on the project > Add > New Scaffolded Item. From the left pane of the Add Scaffold dialog, select Identity > Add. In the Add Identity dialog, select the options you want. Select your existing layout page, or your layout file will be overwritten with incorrect markup.

If you are using project.json then follow this approach.

To use Code Generator package, first you need to include it in project.json like this-

"dependencies": {
  "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
    "version": "1.0.0-preview2-final",
    "type": "build"
  "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
    "version": "1.0.0-preview2-final",
    "type": "build"
"tools": {
  "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
  "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
  "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
    "version": "1.0.0-preview2-final",
    "imports": [

Now you can restore the packages using dotnet restore command. Once it is completed, you can scaffold controllers and views with the following command (or from Visual Studio as shown in official guide)-

dotnet aspnet-codegenerator --project . controller -name HelloController -m Author -dc WebAPIDataContext

The above command will generate controller with name HelloController in the root directory, and views for CRUD options inside Hello folder under Views folder. Please note that, above sample command will help you to create Controller with read write action using model and EF. Without model or dbcontext, it will create empty controller. You can use --help command line switch after controller parameter to get more options about controller generator.

ASP.NET Core 2: Doing scaffolding with dotnet CLI, With dotnet CLI we can: generate projects, solutions, add nuget We call this scaffolding: the generation of areas, controllers, views and pages with predefined code. which will be able to use the aspnet-codeGenerator command. Open a terminal; Go to the directory where you want to create your  Scaffolding DbContext and Models with EntityFramework Core 2.0 and the CLI 07 September 2017 Posted in .NET Core, ef core, command line, CLI. EF Core 2.0 has been out for a few weeks now. If you're looking at an ORM for your .NET application then EF Core should be at the top of the list of possible options.

It is possible to scaffold a controller using below command

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet tool install --global dotnet-aspnet-codegenerator
dotnet aspnet-codegenerator controller -name TodoItemsController -async -api -m TodoItem -dc TodoContext -outDir Controllers

AccountController missing? Razor Class Libraries – dotnet CLI , NET project, either in Visual Studio or using the dotnet CLI. Razor Class Libraries – dotnet CLI Identity Scaffolding NET Core 2.0 or an earlier version, your AccountController controller will be created A Razor Page is like a normal Razor view, which also contains a C# class, through which we can  dotnet-scaffold NAME dotnet-scaffold -- Code Generation tools for .Net framework SYNOPSIS dotnet-scaffold [options] [generator specific options] DESCRIPTION The dotnet-scaffold command is used to scaffold code for your application.

Code Scaffolding with ASP.NET Core, NET Core. Scaffold code properly using the .NET Core code generator CLI tool. tool you can create all of your models, views, and controllers in your ASP. You can read more about other ways of creating this and wiring it up to LocalDb or  The EF Core context and entity classes are in a .NET Core class library. A .NET Core console app or web app references the class library. It's also possible to put migrations code in a class library separate from the EF Core context. Other target frameworks. The CLI tools work with .NET Core projects and .NET Framework projects.

dotnet aspnet-codegenerator command, 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. NET Core web projects with controllers and views. It's not  So, after creating all of my entities (or a subset of them for testing), I set out to look for a CLI alternative to creating new API controllers in Visual Studio. Enter aspnet-codegenerator. Setting up the generator. The aspnet-codegenerator CLI tools require a Nuget package, which is not included by default when creating projects via dotnet new.

Command line scaffolding for ASP.NET vNext, We are tying to get features into your hands as early as possible so that is one To enable command line scaffolding there are a few edits to the want to play around with the views/controllers created in your project to get a  It is possible to specify the exact tables in a schema to use when scaffolding database and to omit the rest. The command-line examples that follow show the parameters needed for filtering tables. .NET Core CLI: