Monday, April 07, 2014

Visual Studio 2013 Update 2 lets you build your own Scaffolder

.NET Web Development and Tools Blog - Creating a Custom Scaffolder for Visual Studio

With the release of Visual Studio 2013 last October, we introduced the concept of Scaffolding to Web Application projects. Scaffolding is the framework on which code generation for MVC and WebAPI is built. For more information on Scaffolding or the MVC Scaffolders check the following blog post: http://www.asp.net/visual-studio/overview/2013/aspnet-scaffolding-overview.

However, the true potential for the scaffolding framework comes from the new extensibility surface released in Update 2. With this new functionality, any VSIX can code against the Scaffolding API surface and have their scaffolds added to the Add New Scaffold Dialog. This blog post will walk through the creation of a custom scaffolder.

To get started make sure you have the following installed on your machine:

Creating a New Scaffolder Project Using Sidewaffle

  1. Go to create a new project.
  2. Click on the C#->Extensibility->Sidewaffle Node.
  3. Select new “Basic Scaffolder”.
  4. Input the desired name of your Scaffolder.
  5. Create the Project.

image

...

Next Steps

Now that you have the basics of creating a scaffolder down, here are some additional resources for what to do next:

Additionally you can look to create more complex scaffolders using the following services:

  • ICategoryRegistrationService – to add new Categories in the Add Scaffold Dialog

  • IServiceRegistrar – to add new ActionServices that you can invoke during scaffolding

  • IRollbackService – to make the services registered above be able to use the Scaffolding rollback feature

  • The Scaffolding.EntityFramework dll – to help with the processing of EF models (this is used by the MVC and WebAPI Entity Framework Scaffolders to create the controllers and for MVC the views)

ASP.NET Scaffolding in Visual Studio 2013

Overview

ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models. Using scaffolding can reduce the amount of time to develop standard data operations in your project.

...

Tutorials

To customize the generated files, see How to customize the generated files from the New Scaffolded Item dialog.

For an example of using scaffolding with Database First development, see EF Database First with ASP.NET MVC.

For an example of using scaffolding in an MVC project, see Getting Started with ASP.NET MVC 5.

For an example of using scaffolding in a Web API project, see Create a REST API with Attribute Routing in Web API 2.

This was pretty lost in the Build news stream, but I think this is going to spawn some very interesting Extensions in the near future.

No comments: