Adding a Template Property
CodeSmith Generator uses property directives to define the metadata for a template. You need to add one property directive to the template for each piece of information that you want to collect from the user when the code is generated. Here are the property directives we'll need for our AssemblyInfo.cst template:
<%@ Property Name="Author" Type="System.String" Description="Lead author of the project." %> <%@ Property Name="Title" Type="System.String" Description="Title of the project." %> <%@ Property Name="Description" Type="System.String" Description="Description of the project." %> <%@ Property Name="Configuration" Type="System.String" Default="Debug" Description="Project configuration." %> <%@ Property Name="Company" Type="System.String" Default="MegaUtilities, Inc." %> <%@ Property Name="Product" Type="System.String" Description="Product Name." %> <%@ Property Name="Version" Type="System.String" Default="1.0.*" Description=".NET assembly version." %> <%@ Property Name="FileVersion" Type="System.String" Default="1.0" Description="Win32 file version." %>
Each of these properties has a name (which we'll use to refer to the property in scripting code), and a type (in this case, they're all strings). Some of the properties also have default values, although, as you can see, you're not required to supply a default value for a property. Most of the properties also have a description. When the user selects a property in the template's property sheet, CodeSmith Generator displays the description to help them enter the proper data.
The next step is to make the connection between these properties and the spots in the template where we want to output their values.