2

Is it possible to add custom scaffolding templates to Visual Studio 2017 community for things like MVC Controllers and Views?

I've seen a number of tutorials which suggest adding custom templates to the following locations but nothing seems to work:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates
C:\Users\<user>\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\2.0.4\Templates

For example, if I want to add a new Controller via the right-click menu, any custom templates added to the above locations just do not show. Likewise the View templates do not appear either.

weblar83
  • 681
  • 11
  • 32
  • See [Writing custom Code generator for Dotnet Core](https://stackoverflow.com/questions/41352970/writing-custom-code-generator-for-dotnet-core). – Mark G Jun 25 '18 at 17:31
  • @MarkG Thanks for your comment. Does your link then produce an output which can integrate with VS2017's custom templates? Or does this just allow code generation via the command line? What I'm wanting ultimately, are a custom set of Controller/View cshtml files which when generated, match the underlying business objects of our application. – weblar83 Jun 27 '18 at 08:00
  • Command line only, see [explanation here](https://github.com/prafullbhosale/CustomAspNetCodeGeneratorTemplate/issues/2). – Mark G Jun 27 '18 at 23:10

1 Answers1

3

Ok, so the following steps work:

Copy the Templates folder from the following location to the root of the project directory:

C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.visualstudio.web.codegenerators.mvc\<version>

In VS2017, when adding a Controller or View, the selected scaffold is then brought in from the local Template directory residing within the project. These can be tweaked and changed as necessary.

It looks as though it is not possible to "add" to the scaffold list.

weblar83
  • 681
  • 11
  • 32