Chapter 14Code Generation with T4

Wrox.com Code Downloads for this Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/professionalvisualstudio2015 on the Download Code tab. The code and any related support files are located in their own folder for this chapter.

Frequently, when writing software applications, you'll have large areas of boilerplate code in which the same pattern is repeated over and over. Working on these areas of code can be ­time-consuming and tedious, which leads to inattention and easily avoidable errors. Writing this code is a task best suited to automation.

Code generation is a common software engineering practice where some mechanism, rather than a human engineer, is used to write program components automatically. The tool used to generate the code is known as a code generator. A number of commercial and free code generators are available in the market, from the general to those targeted toward a specific task.

Visual Studio 2015 includes a code generator that can generate files from simple template ­definitions. This code generator is the Text Template Transformation Toolkit, or more ­commonly, T4.

This chapter explores the creation, configuration, and execution of T4 templates. You'll also see how to troubleshoot templates when they go wrong. Finally, ...

Get Professional Visual Studio 2015 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.