Create Your Own Scaffold in Visual Studio 2013.2
An important part of ASP.NET MVC is the set of code generators called scaffolds. Inspired by Ruby on Rails, these code generators can be used to quickly create controllers and views based on a model class. While development can be done without them, it often requires quite a bit of boilerplate code that, if coded incorrectly, will compile but fail at runtime.
ASP.NET Scaffolding is considered to be a new feature for Visual Studio 2013, but ASP.NET MVC has had comparable tooling support for several versions now. What’s new in VS 2013 Update 2 is the ability to create your own scaffolds that plug into the overall framework. The process starts with the Basic Scaffolder project type.
After setting the header information (name, version, etc.) you need to decide whether or not to display a custom UI. This UI, invoked via the ShowUIAndValidate abstract method, should be used specifically for soliciting the user for additional options. If not needed, simply override the method to return true.
Joost de Nijs continues,
Now that the scaffolder has the user inputs necessary to do your scaffolding (and you have persisted that data), it is time to modify the project. There are several types of actions built into the Scaffolding Framework to help you build your scaffolder, these are in the ICodeGeneratorActionsService interface of the Microsoft.AspNet.Scaffolding.12.0 dll. Of course you can create your own actions, but the benefit of using the method calls exposed by the Scaffolding Framework is that they can be Rolled Back in case any step of the Scaffolding Fails. Rolling back will return the project to the state it was in prior to the scaffolder being invoked.
Creating new folders and static files is straight forward, just call the correct Action Service method. But for real work you’ll need to learn how to write T4 templates.
ASP.NET MVC grew up with NuGet, so it isn’t surprising that Scaffolder projects include the ability to programmatically install NuGet packages.
Tom Gilb & Kai Gilb Jan 26, 2015