This tip will help you to create, then start extending, a basetemplate class of your own that can hold your favorite library routines, and also have base class access to the cool functions found in the SQLSchema and OutputFileCodeTemplate class.

1.Start by copying the sample project’s CustomProperties and BaseTemplates subdirs from \Program Files\CodeSmith\v3.2\SampleProjects into your SW dev tree (I used ModifiedCodeSmithSamples as my parent dir name). This step protects your base class and the Codesmith source and assemblies it depends on from changes in the Samples when new versions of Codesmith are released. If you like the new samples, you can incorporate them at a time convenient to you. It also keeps the original sample untouched,

2.Start VS 2005, and in a solution in which you plan to use Codesmith to create some of the code, create a solution folder called BaseTemplates. Add the two projects found in the two sample project subdirs you just copied into your SW dev tree directory . (You could also choose to create a a whole new solution to house the new MyBaseTemplate project and these two dependencies).

3.Expand the CustomProperties project, and work with it:

·Delete the "missing" references to GUI and Engine, and add references that point back to the corresponding .dlls in the \Program Files\CodeSmith\v3.2\bin dir (CodeSmith.Gui.dll and CodeSmith.Engine.dll)

·Delete the GlobalAssemblyInfo.cs file from the project.

·Change the project's signing Secure Key File to a .snk file of your own. Reference “tips for creating strong named assemblies” in VS 2005 help for info on creating a .snk file.

·Build the Assembly.

4.Expand the Codesmth.BaseTemplate project, and work with it:

·Delete the "missing" references to Engine, and add a reference that points back to the .dll in the \Program Files\CodeSmith\v3.2\bindir.

·Add a reference to the CustomProperties project you just built (Select "Projects" tab in the AddReference dialog box).

One minor annoyance if you are working on your base template class. Codesmith seems to have a tendency to get an out-of date version stuck in its template cache here: \Documents and Settings\All Users\Application Data\CodeSmith\v3.2\Template Cache

I often clear this directory out, if I’m working on base template changes and they don’t seem to be working right, or even appearing at all. The problem also sometimes manifests as the inability to compile the templates built on the MyBaseClass. I’m pretty prone to making mistakes, so sometime I can’t tell if it is a caching problem or my fat fingers… but clearing the cache never hurts…

Hope you find this tip useful! Please post any corrections or expansions on this tip you think of.