Writing your first template

Running templates that others have written is the first step with CodeSmith Generator. To get the full benefit of Generator in your day-to-day work, you'll write your own templates. In this tutorial you write a template from start to finish. It generates an AssemblyInfo.cs file for a C# project.

Steps

  1. Spot the need: find a repetitive task worth generating.
  2. Create the template: add the CodeTemplate directive.
  3. Start with the result: decide which parts of the output are static, calculated or supplied by the user.
  4. Add static content: paste the finished output into the template.
  5. Make the content dynamic: calculate values with expressions.
  6. Add template properties: declare the values the user supplies.
  7. Use properties in the template: insert property values into the output.
  8. Generate code: run the template.

Next: Spot the need