Missing Scaffolding Engine Components in ASP.NET Core Projects

Yesterday I went to create a ASP.NET Core MVC web project in Visual Studio, and found that there was no scaffolding available when creating a new controller.  Right clicking on the Controllers folder, there was no Controller option in the Add sub-menu, and no option to select scaffolding after clicking New Item and selecting MVC Controller Class.  During the project creation, I had selected No Authentication.  In researching why scaffolding would be missing, I came across the following warning in one of the ASP.NET Core tutorials:

You must have the Authentication set to Individual User Accounts in this release for the scaffolding engine to work.

So, go back and create a new project using Individual User Accounts, and sure enough, it works!  Suspecting that there was some component missing, I compared project.json between projects using the WinMerge tool which showed that, apart from the expected items for EF and authentication, there are two missing dependencies and a missing tools registration.

To add scaffolding to an ASP.NET Core Web project using No Authentication, simply add the following items to project.json in the dependencies section:

    "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"
    }

Then add the following to the tools section in project.json:

    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8"
      ]
    }

Save project.json, the dependencies should be restored automatically, and then scaffolding should work.  This was done on Visual Studio 2015 Community with Update 3.  The .NET Core 1.01 – VS 2015 Tooling Preview 2 was also installed.  I also noticed that selecting the other authentication types, such as Windows Authentication, also have a project.json missing the CodeGeneration tools.  I am hopeful that Microsoft will update the templates eventually.

Leave a Reply

Your email address will not be published. Required fields are marked *