Practical Code Generation in .NET: Covering Visual Studio 2005, 2008, and 2010 Book Review
|When it comes to code generation I have seen the worst of the worst and some really cool implementations.|
The worst was on a large government project. The consulting firm created a custom code generator that created every layer of the 5 layer application. In truth, the only reason the project was so large was because of the effort that went into the implementation and maintenance of the code generation application. As time went on the firm lost all control of the relationship between the generated code and the application that created it. Maintenance teams needed to be in place for both the production code and the generation tool. Needless to say a ton of money was wasted on the project.
The best was the use of the GAT and GAX tools to put code generation tools in place to support a Software Product Line Engineering project. The tools generated project shells, added different components based on wizard selection, built configuration files, and included item level recipes. The code generation tools didn't attempt to control the application implementation, it only enhanced it. It was used to increase productivity and help enforce consistency.
I was glad to find that the author does not attempt to implement a grandiose code generation monstrosity like the consulting firm did in my first example. He actually does a really great job of warning the reader to not go overboard with code generation.
The book covers Visual Studio Add-ins, generating code with the CodeModel, FileCodeModel, VsWebsite, and VSLangProj, generating solutions and projects, modifying text in the code editorT4 Templates, item templates, and attributes.
The book ends with 3 sizable case studies. They include Generating a Connection String Manager, Generating Validation Code, and Generating Data-Conversion Code. You can read Generating a Connection String Manager on the informIT web site.
The biggest let down I found with this book is the downloadable code. The author has 2 of the case studies available for download, but does not have sample per chapter available. You also need to install DSL Toolkit to get the Generating Data-Conversion Code project to load in Visual Studio 2008, but it didn't load in Visual Studio 2010.
One of the things I like the most about the book is that the author really shows you how to take advantage of existing tools and libraries that are intended to be used for code generation. In the large government project I mentioned above, they re-invented every size wheel you can think of. Everything was done from scratch and did not take advantage of any of the framework tools.
Over all I would recommend this book to anyone interested in code generation with the .NET framework and Visual Studio. It will definately get you moving in the right direction.
Practical Code Generation in .NET: Covering Visual Studio 2005, 2008, and 2010 (Addison-Wesley Microsoft Technology Series)