Spotting the Need
Think about your average day of software development. Some of it probably involves brand-new innovative work that breaks new ground and doesn't resemble anything that you've ever done before. But other parts are probably more routine. Whether it's writing the code for a public property backed by a private variable, creating an About This Application dialog box for a new product, or designing a new page for the corporate Web site, much of your day probably involves routine coding tasks that you've done before with only minor variations.
Any time you find yourself doing one of these repetitive tasks, you've found a candidate for code generation. Creating source code files (or Web pages, or SQL statements, or HTML pages, or any other text file) with minor variations is exactly the sort of thing that CodeSmith is designed for. For example, if you're writing C# code, you know that every C# project contains an AssemblyInfo.cs file with metadata about the project. Visual Studio .NET automatically creates a skeleton AssemblyInfo.cs file for you when you create a new project, but it's full of comments designed for the novice developer, and attributes for every conceivable purpose. That's fine as a teaching tool, but it's not what most developers want to see in their source code. So typically, you'll start a new project by cutting out the junk, adding a few comments of your own, and making a standard set of changes to the attributes that remain. That's a perfect candidate for code generation: a process that you do over and over again with a few variations. Let's use CodeSmith to generate just the AssemblyInfo.cs file that you need, without all the fluff.
Next: Creating the Template