Design-time T4 text templates let you to generate program code and other files in your Visual Studio project. Typically, you write the templates so that they vary the code that they generate according to data from a model . A model is a file or database that contains key information about your application’s requirements. For example, you could have a model that defines a workflow, either as a table or a diagram.
For example, you could create a template to define an HTML page: <html><body> The date and time now is: <#= DateTime.Now #></body></html> Notice that the template resembles the generated output.
Watch Overview on Channel 9 Text Template Transformation Toolkit (T4) is a template-based code generation engine. It is included with Visual Studio 2008 and available as a download for Visual Studio 2005 in DSL and GAT toolkits. You can use T4 templates to generate Visual Basic, C#, T-SQL, XML or any other text files.
This post is a part of the series that introduces code generation with Text Templates (also known as T4 Templates) in Visual Studio using C# and Visual Basic; explains how to create reusable templates and combine them in complex code generators. In order to follow examples in this article, you need to have Visual Studio 2008 or 2010 Standard Edition or higher, SQL Server 2005 or later, T4 Toolbox and T4 Editor installed on your computer. Introduction In the first article of this series, we created the following text template to generate a DELETE stored procedure for a given database table using SMO . This stored procedure is one of the CRUD procedures that would need to be created to encapsulate access to this table.