When creating controller in MVC 6 I don't see the scaffolding for creating controller methods? Will they be missing or in the production release?
6 Answers
The namespaces have changed in Core 1.0
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview1-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview1-final"
info from:
https://wildermuth.com/2016/05/17/Converting-an-ASP-NET-Core-RC1-Project-to-RC2
-
This is the correct answer !!! Just downloaded those dependencies and the "New Scaffoding Item" option appeared. Dec 23, 2016 at 20:03
-
On VS2015 Community using Asp.Net Core v1.1 I am seeing the CRUD scaffolding tools in the Context menu but they are greyed out and the Using Add > New Item gives me now Controller with View option either. Have restarted VS and machine to no avail.– K7BuoyFeb 2, 2017 at 14:56
-
I get a conflict error when trying to add this to a new project based on templates for Web API.– EdwardFeb 13, 2017 at 1:32
If you are referring to CRUD scaffolding for controllers and views with ASP.NET 5 and MVC 6, it has been split off from the Visual Studio GUI and moved to command line.
You'll need a package called CodeGenerators
, add it to your project.json configuration file as:
"dependencies": {
...
"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta4",
...
},
At the moment VS does not offer GUI command to perform scaffolding but you can give a look to this link :
-
"k gen" command does not exist in VS 2015 RC? what is the command for dnv?– MostafaMay 4, 2015 at 23:27
-
I found the command in VS 2015 RC for scaffolding: `dnx . gen controller -name NameOfController --dataContext DBContextName --model NameOfModel'– MostafaMay 4, 2015 at 23:44
-
Package Microsoft.Framework.CodeGenerators.Mvc 1.0.0-beta4 is not compatible with net452 (.NETFramework,Version=v4.5.2). Package Microsoft.Framework.CodeGenerators.Mvc 1.0.0-beta4 supports: - dnx451 (DNX,Version=v4.5.1) - dnxcore50 (DNXCore,Version=v5.0) One or more packages are incompatible with .NETFramework,Version=v4.5.2.
– EdwardFeb 13, 2017 at 1:21
Command line syntax for scaffolding controllers in MVC 6 is:
dnx . gen controller -name NameOfController --dataContext DBContextName --model NameOfModel
-
2This is silly in my opinion. Why remove essential tooling and go command line? Jun 3, 2015 at 14:00
-
-
I have ask many times about why MS remove the script Bundling and Minification, and ms said :( ASP.NET 5 is complete rewrote and new gen web development.)– CheungJun 15, 2015 at 14:21
-
1@CrazyCoderz I guess they wanted it to be cross-platform and don't depend on VS. But I'd expect support added to VS soon since it just needs to make a call to the code gen.– oradJun 1, 2016 at 20:13
At least as of the latest Visual Studio 2015 Update 1, ASP.net 5 RC (update1) scaffolding is integrated into Visual Studio.
To do so include the following in your project.json file:
"dependencies": {
...
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-*",
...
Then you can find it by right clicking the Controllers directory -> Add -> New Scaffolded Item
-
Hi, I did this but don't see the option like you mentioned. Also tried restarting VS. Any idea?– SvenJun 15, 2016 at 22:12
-
@Sven Note the package to include depends on your VS/ASP version, see plumdog's answer for how to make it work with later versions.– RickJul 27, 2016 at 14:09
-
I downloaded this dependency and nothing happenned. There is no "New Sacaffodilg Item" created... Dec 23, 2016 at 20:00
It has been painful getting this to work in VS2015 following an upgraded to 1.1 but the following dependencies and tools in your project.json should work if you connecting to SQL to scaffold out your entities too.
{
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGeneration": "1.1.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.1.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore": "1.1.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.1.0-preview4-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.1.0-preview4-final"}
}
Doing the following should resolve your issue.
- Open VS2015=>TOOLS=>Customize.
- Select Commands.
- Select Context menu.
- Select Project and Solution Context Menus|Folder|Add.
- Check that 'Controller' appears.
- Move up Controller item to the top.
- Restart Visual Studio.
-
This solution does nothing... only appears the Controller disabled. Dec 23, 2016 at 19:57
-