Start with the result
The easiest way to build a CodeSmith Generator template is to start with an example of the code you want to generate: in this case, a finished AssemblyInfo.cs file. You use this one throughout the tutorial:
using System.Reflection;
using System.Runtime.CompilerServices;
//
// Created: 1/1/1973
// Author: Blake Niemyjski
//
[assembly: AssemblyTitle("User storage utility")]
[assembly: AssemblyDescription("Helps manage data in Isolated Storage files.")]
[assembly: AssemblyConfiguration("Retail")]
[assembly: AssemblyCompany("MegaUtilities, Inc.")]
[assembly: AssemblyProduct("StorageScan")]
[assembly: AssemblyCopyright("Copyright (c) MegaUtilities, Inc.")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0")]
[assembly: AssemblyDelaySign(true)]
Sort the content of the file into three kinds:
| Kind of content | In this example |
|---|---|
| Content that never changes | Everything else, treated as static text. |
| Content Generator can calculate | The creation date on the // Created: line. |
| Content you prompt the user for | The author, title, description, configuration, company, product, version and file version. |
Make these decisions based on how you'll use the template. For example, this template always sets the AssemblyDelaySign attribute to true. If that value varied from project to project, you would make it a dynamic part of the template and prompt the user for it.
Note
Templates can also contain conditional logic. For example, you could prompt for an AssemblyDelaySign value and include extra attributes in the output only when it's true. This tutorial doesn't need that.
Now that you know what you want to build, it's time to put the content into the template.
Next: Add static content