1

MVC 5 has the very handy feature when creating a view to be able to select a template for scaffolding out the view. This uses a T4 template file to generate a CSHTML file based on a specified type.

Is there a way to do anything like this in ASP.Net Core 1.0?

Rono
  • 3,171
  • 2
  • 33
  • 58

3 Answers3

7

You need to add references on Tools. But only for build time

in project.json, add the following to 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"
}

Still in project.json, locate the tools section and add the following

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

Add following line in project.json under dependencies.

"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final"

Also, add following under tools

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final"

Save the file and it should restore the packages, restart Visual Studio if necessary.

Now when you right click, you should see 'New Scaffolded Item...' option under 'Add'

parveen
  • 1,939
  • 1
  • 17
  • 33
  • These steps do expose the UI for scafolding but I am getting errors when i try to scafold something.."Version for package 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' could not be resolved (.net core 1.0.0. with tools update 3) – Martin Kearn Jul 13 '16 at 14:16
  • Try removing this line and save, then add again and save. While doing this check Package Manager output, make sure the package is getting downloaded. It should show you whats happening while restoring. – parveen Jul 13 '16 at 15:40
0

I know this is old, but for me it was solved by opening the myProject.sln, it loaded the solution and then controller, etc options were available.