CodeSmith

I have started to look at using codesmith for a project I am working on and so far I am very impressed with the tool. (Eric , the code smith himself, is looking for some legal aid if you are so qualified/inclined.) There are a couple of things that I am trying to figure out how to incorporate into the generation process, and as far as I can tell they are not there yet.

  • The first is the ability to do batch processing. I want to be able to point to a database and then create stored procedures for each table.
  • The second is the ability to save the generated script or code to a file after it is generated.

I think I can accomplish both of these things in the actual template, but it would be much smoother to keep each template individual and have the tool do the batch processing and saving of the files. I know Eric has alot more to worry about right now then adding new features to the tool, but I figured I would throw these out there nonetheless. The last thing, which might just be my ignorance, is a way to edit the compiled template directly.

Eric is also toying with making the project open source, this decision is of course completely up to him, but I would love to see him package it as a small software package and make a little money from it. I would be in line as one of the first to buy it.

[James Avery]

Thanks for the glowing review!

Here are a some things that have been on my TODO list and should address your needs:

1. Create CodeSmith Batch (.csb) format.  This will basically turn CodeSmith into a scripting engine with the powerful addition of being able to select properties to drive the script.  This combined with #2 and #3 will enable CodeSmith to be a very powerful batch processing engine.

2. Add a designer for the DatabaseSchema object so this can be selected as a property for your template or batch file.

3. Create a CodeTemplateProperty directive.  This will enable you to specify a template (.cst file) to be compiled and added to your batch or template as a property.  This will enable you to do something like:

<%@ Batch Language="C#"
   Description="Generates one big SQL script of stored procedures for an entire database." %>
<%@ Property Name="SourceDatabase" Type="SchemaExplorer.DatabaseSchema" %>
<%@ CodeTemplateProperty Name="StoredProcedureTemplate" Src="StoredProcedures.cst" %>
foreach (TableSchema table in SourceDatabase.Tables)
{
   StoredProcedureTemplate.SourceTable = table;
   StoredProcedureTemplate.Render(this.Response);
}

4. Create a command line interface for CodeSmith.  I am not sure how I will implement this, but I really want to be able to use CodeSmith on the command line.

Also, in the CodeSmith window there is a "Save Template Output" button.  This allows you to save the generated output to a file.  Also, you can set the default filename for the template by overriding the GetFileName method (see the CSharpTypedCollection.cst for an example of this).

3 Comments

  • This is awesome. I can't wait to see some of these improvements and would gladly volunteer some coding time if you need it.





    -James

  • With batch processing generation support it would be neat to have an NAnt task which can be used to generate code.

  • The NAnt idea is great! I will add this to my TODO list. Thanks!





    Of course, none of this will matter until I can get CodeSmith legally transfered to me. :-(





    Eric J. Smith

Comments have been disabled for this content.