MyGeneration vs. CodeSmith

Comparing two software tools to generate C# code and sql scripts based on a specification in MS Excel.

What I needed to do

Recently I needed to generate some hundreds C# classes and sql scripts (some visio diagrams too) based on an Excel specification. I started using MyGeneration, as it is open source and I had used it some years ago, so there was no start-up time, and I could stay to my time schedule. After some days, I wanted to try CodeSmith, which had been used in a company I worked for. I had no personal experience, however I think quite many know and use it.

How I wanted to do it

I decided to write a simple c# console application to convert excel sheets into xml and xsd files, which could be used as data source for code generation. This was in fact imitation of specification in a modelling tool and exporting the specifiation into xml directly from this tool.

Why code generation?

At first some general well-known reasons, why code-generation can be of value in some cases (for those who think, they have to take care of each line of code personally):

  • reducing coding time for repetitive patterns
  • increasing fun to create stereotype code
  • reducing number of bugs
  • increasing the ability to adhere to coding standards
  • reducing the time between the last change in specification and creating complete code base

Simple comparison

I had only a few days to do the tasks and use these tools, so only a brief comparison follows:

Tool: MyGeneration CodeSmith
Latest version: 1.3.0.3  5.1.1
Number of downloads: 141,147 Anybody a guess?
Last version added: December 13, 2007  May 18, 2009
Searching in sources: Only first occurrance No last searches *
Intellisense: Very bad – works only occasionally Very good and helpful
Xml as data source support: Very limited, however usable Excellent
Merge support: Using partial classes Supporting regions
Price: free USD 299 **
Batch processing: Yes Yes
Auto sql script execution: No Yes
CodeDom parser: No Yes ***
C# 3.0 Support (incl. LINQ): No Yes ****
IndexedEnumerable: No Yes *****
Caching problems: No Yes ******

* In MyGeneration, you can find only first occurrance of an expression. If you want to find other (works fine in CodeSmith), you have to go to the beginning of the document and press Ctrl+F once more. However it has combo box with the list of last searches, which is missing (?!) in CodeSmith editor.
** Price for professional edition for a single developer in one organization. Licence can be transferred from one developer to another. CodeSmith Site License costs $2999 (25 developers at one physical location). Additional $99/user/year for Premier support.
** Your data source can be C# code – you get in fact CodeCompileUnit.
*** You can use C# 3.0 in the template editor.
**** Having index in foreach loops is really handy.
***** Caching is meant as a nice feature of CodeSmith, however becomes a hell, if you have to close/open your template editor after each change in your xml/xsd data source. Not having time to search for a better workaround/fix. [Update; See Eric's comment, how caching is intended to work. I still think, changes of xml/xsd made in Studio should be monitored automatically]

To Sum it up

I must say I am rather disappointed by the templates editors, especially in the case of CodeSmith, as I would expect really a better experience for 300 bucks. Not reflecting changes in your data source was really annoying, as you think you have a coding error somewhere, until you find yout you just have to open and close your editor. It is even more suprprising, if you consider CodeSmith is recommended by professionals since a long time. If you plan just one-shot generation, I would recommend using MyGeneration and just ignore the problems with Ctrl+F (however hard it is). If code generation is a more often theme in your company, definitively consider buying CodeSmith (and hope that Premier support will clarify the problems with caching), as the definitive solution – writing your own code generating software – does need some larger investments (although not unusuall).

Comments (6)

Eric J. SmithJune 12th, 2009 at 6:36 pm

The caching thing is on purpose. It only happens in Studio. The idea is that inside of Studio, you are working on templates and having your metadata change unexpectantly could cause issues as well as having to retrieve expensive metadata every time you try a minor change could be expensive. There is a button above the propertygrid to force the values to refresh. And there is also an option in Studio to make it always refresh like it does when running templates outside of Studio.

adminJune 13th, 2009 at 12:13 am

Thanx Eric, I am really astonished how quickly your reponse reached my post.

alvarJune 17th, 2009 at 10:22 pm

Unfortunately the refresh button does not work – I edited xml in template studio, saved it, ran cst generation using F5 and changes from xml file have not been adapted. Closing and opening studio helps always.

Eric J. SmithJune 24th, 2009 at 6:04 pm

You are clicking on the Refresh Values button? What property type is it? Is it an XmlProperty?

Eric J. SmithJune 24th, 2009 at 6:07 pm

Also, I guess I didn’t get notification of your comment last time. So it may be better to have this conversation with our support team (support @ codesmithtools.com) where it will definitely get tracked and handled.

alvarJune 25th, 2009 at 7:04 am

I have contacted support, let’s see what happens.

Leave a comment

Your comment