Skip to content
Sean Kearney edited this page Apr 24, 2013 · 4 revisions

Sample Solution Overview

The sample solution contains three projects:

  • Sitecore.Master - The sample TDS project. This contains sample content items, templates and fields that are used to demonstrate code generation.
  • SampleLibrary - A C# class library project that will be the destination of the generated classes
  • Extensions - A C# class library project containing useful extension methods that can be used in your T4 template

Provided T4 Templates

  1. Helpers.tt - This file contains simple helper functions that may be useful to T4 template authors. This helper file can be referenced in your own .tt files via the <#@ include file="Helpers.tt" #> directive.
  2. GlassHeader.tt This file is used to generate a set of using statements and base classes required by the Glass framework.
  3. GlassItem.tt This file is used to generate code for Glass Item Mapper interfaces and classes.
  4. VelirHeader.tt This file is used to generate a set of using statements required by the CIG framework.
  5. VelirItem.tt This file is used to generate code for CIG classes.
  6. ItemPaths.tt This file generates a set of classes that allows you to have Sitecore items paths with intellisense as demonstrated by Kern Herskind Nightingale
  7. MDDocHeader.tt This file is used to generate a header for the Markdown documentation file.
  8. MDDocItem.tt This file is used to generate Markdown formatted documentation for the items in the TDS project.
  9. The Extensions Project - See Using Extensions Methods

Required Assemblies

Depending on the framework you are generating code for, there are assemblies that are required in order to compile the project. Please see the $(SolutionDir)\lib\Readme.txt file for a list of assemblies you must reference.

Compiling the Solution

Visual Studio needs to be running as an Administrator in order to compile. This is due to a post build step on the Extensions project. Please see Using Extensions Methods for more information.

Configuration

By default the TDS project is configured to generate Markdown documentation; this isn't typically what you would use code gen for. To generate code for either Glass or CIG:

  1. Go to the code generation properties of the TDS project
  2. Change the "Code Generation Target File" to TdsT4CodeGeneratedFile.cs
  3. Change the "Header Transform File" to GlassHeader.tt or VelirHeader.tt
  4. Change the "Base Project Transform File" to GlassItem.tt or VelirItem.tt
  5. Right click on the TDS project and choose "Re-Generate code for all items"

Now, in the SampleLibrary project you should have a file called TdsT4CodeGeneratedFile.cs. Within that file you should have classes that conform to your specific framework!

Advanced Configuration

There are more advanced configurations of code generation as well.

  • Each item in your TDS project can configure a different T4 template. This would allow you to generate different code for different trees of items.
  • You can pass custom parameters with the item by using the 'Data' property.