Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To insert the value of a property in the generated output from the template, use the same   <%= and %> syntax that you used with calculated fields, but this time use the name of the property for CodeSmith to evaluate. Here's our final template:

Code Block
languagecsharp
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Create an AssemblyInfo.cs file." %>

...


<%@ 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." %>

...


using System.Reflection;

...


using System.Runtime.CompilerServices;

...


//

...


// Created: <%= DateTime.Now.ToLongDateString() %>

...


// Author:

...

   <%= Author %>

...


//

...


[assembly: AssemblyTitle("<%= Title %>")]

...


[assembly: AssemblyDescription("<%= Description %>")]

...


[assembly: AssemblyConfiguration("<%= Configuration %>")]

...


[assembly: AssemblyCompany("<%= Company %>")]

...


[assembly: AssemblyProduct("<%= Product %>")]

...


[assembly: AssemblyCopyright("Copyright (c) <%= DateTime.Now.Year.ToString() %> <%= Company %>")]

...


[assembly: AssemblyCulture("")]

...


[assembly: AssemblyVersion("<%= Version %>")]

...


[assembly: AssemblyFileVersion("<%= FileVersion %>")]

...


[assembly: AssemblyDelaySign(true)]

Note that a single property (such as Company) can appear at multiple places in the template.

...