Make the content dynamic

Next, let CodeSmith Generator calculate the parts of the output it can work out for itself. You do this by adding C# code to the template with the same scripting tags as ASP.NET. Generator treats anything between <%= and %> as an expression: it evaluates the expression when the template runs and writes the result to the output in its place.

This version of the template uses two expressions: one replaces the hard-coded creation date, and one adds the current year to the copyright notice:

<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Create an AssemblyInfo.cs file." %>
using System.Reflection;
using System.Runtime.CompilerServices;
//
// Created: <%= DateTime.Now.ToLongDateString() %>
// 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) <%= DateTime.Now.Year.ToString() %> MegaUtilities, Inc.")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0")]
[assembly: AssemblyDelaySign(true)]

Now Generator fills in the creation date and copyright year every time the template runs. Other parts of the file, such as the assembly title and description, can't be calculated. For those, you prompt the user with template properties.

Next: Add template properties