Nov 16 2007

CodeSmith CodeTemplate attributes

Category: ApplicationsRory Primrose @ 08:03

I have been playing with CodeSmith recently. I have created a NAnt script that compiles and executes a set of CodeSmith templates based on a project definition and also integrates with TFS for any changes. I did come across a problem recently with CodeSmith being able to compile my templates though.

The naming of my .cst files included format masks that my NAnt script can use to determine the template output filename rather than being defined by the template itself. The issue here is that CodeSmith by default takes the template file name and uses that as the compiled class name.

CodeSmith correctly handles special characters, so a filename like dbo.sp{3}Delete.proc.sql.cst would be correctly compiled. This example is actually fine, but there is a bug in CodeSmith if the template name (after special characters are stripped) starts with a number, {3}DeleteDac.Community Server.cst for example. In this case, the special characters are stripped correctly, but the class name will start with a number which causes a compiler error in C#.

I contacted CodeSmith support regarding this issue. Their response was to use a ClassName and Namespace attribute on the CodeTemplate directive to use a more appropriate name. Interestingly, I couldn't find any references in the CodeSmith help regarding these attributes.

Tags: ,

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading