Tips and tricks

Generating many files

  • Use one sub-template per file. When one generation run needs to produce several files, call a sub-template for each file from a master template and write each one with the RenderToFile method.
  • Automate with projects. To generate multiple output files as part of an automated process, use a Generator project from the command line or MSBuild.

Working with templates

  • Drag and drop templates. Drag a template from Template Explorer to any application that accepts dropped text. Generator shows the template's property sheet; fill it in, click Generate, and the output goes straight into the application where you dropped the template.
  • Use strongly typed XML. The XmlProperty directive gives you a strongly typed object model and statement completion for metadata stored in XML files.
  • Write trace messages. Use Trace.WriteLine to write messages to the Debug output window while you debug a template.

Mixing generated and custom code

  • Use active generation. Mix your own code with generated code by using one of several active generation strategies.
  • Preserve custom code. Use merge strategies to keep custom code when you regenerate from templates as part of an automated build.

Databases

  • Run generated SQL automatically. If you generate SQL scripts, Generator can execute them right after it generates them.
  • Generate stored procedures. Use the StoredProcedures.cst sample template to generate standard create, retrieve, update and delete stored procedures for a table instantly.