If you read my blog, you know how much I love writing code that writes code.  CodeSmith is my favorite tool for this, and I just found a way for you to get it for free!!

http://weblogs.asp.net/scottdockendorf/archive/2005/07/26/420584.aspx

get em while you can!!

with 0 Comments
I just posted a template in the CodeSmith Template Share forum that uses XML with sp_xml_preparedocument, OPENXML, and sp_xml_removedocument to accurately script out data in a SQL Server table.

Some highlights of the template:
  • The original table data is copied into a new table for backup.
  • If a TargetDatabase is defined, the script will include a "Use" statement.
  • If a TargetDatabase is defined, and the AutoExecutescript property is true, the ouput will be executed on the target database
  • If the current table has an identity column, the seed is maintained.
  • The entire operation is handled in a Serialized Transaction.
This template was built and tested with CodeSmith 3.0

Check it out, and give me some feedback...  how does it compare to the template that ships with CodeSmith?  Anyone got any ideas for enhancing this template to handle Binary data?

tc
with 0 Comments

My favorite Code Generator just got a huge upgrade... 

A New site and a new release.

Ever wanted more time to get a project done?  This tool has saved me so much time in the last year.  After you get your templates generating your code the way you like, CodeSmith 3.0 will practically make time for you.  CodeSmith 2.6 has paid for itself many times over, and I expect that CodeSmith 3.0 will continue this trend.

Some things I like about CodeSmith 3.0:

XML Properties


  • Generate and XSD that defines your structure, and add the property attribute to your template.  The property grid will let you pick an xml file to populate the property.  You can now create your own metadata.  Create your own mapping scheme they way you want it.

Code Completion


  • One of the hardest things to pick up with CodeSmith is how powerful the Schema Explorer is.  It was documented in 2.6, but with Code Completion, the learning curve is ¼ what it was in CodeSmith 2.6

Built In Merge Strategies


  • If you are not using Active Generation1, but want more automation than Passive Generation2 can give you, then Merge Strategies are your ticket.  Specify regions in your code that are either replaced when the CodeSmith console is run, or are preserved. Either way, it allows the developer the freedom to blend Passive and Active code generation for the ultimate in "Your Code, Your Way"

CodeSmith 3.0 is well worth purchasing at twice the price.  Eric Smith doesn't know what he has.  He has really taken a good tool and made it great.


1Active Generation = The developer will not edit the code generated with the intention of re-generating the code when changes are needed
2Passive Generation = The developer may edit the code generated with no intentions of re-generating if changes are needed. Changes will be made by hand

with 0 Comments

If you are new to code generation (even if you are not!) you need to get a copy of CodeSmith 2.6.  This app is the cats meow when it comes to templated code generation.  Eric Smith has really out done himself (is it really just one guy??).  Here are the features he listed in his release email:

- Syntax highlighting of both template and target languages.
- Much improved Visual Studio .NET custom tool.
- Outlining support.
- Line modification markers.
- CodeSmith Studio is now a single instance application.
- Improved compiler and template execution performance.
- Better Unicode support.
- Tons of other minor improvements and bug fixes.

He left out many more, but my favorite has got to be the “Template Code Expansion”.  Imagine an ASP 3.0 page with code and HTML intermingled.  Press Ctrl+Shift+M and watch the code collapse into hidden regions just like ASP.Net.  Very cool, and CodeSmith supports code behind as well.  As matter of fact, CodeSmith allows you take advantage of the full .NET framework to help you generate _YOUR_ code. 

Think about what ASP.Net has done for generating HTML?  Sure you could write that HTML by hand, but it really gets powerful when you can generate an HTML table row for each row in a table.  CodeSmith brings this same paradigm to code generation.

Nothing is cooler than code that writes code, and CodeSmith is the king of code generation.  Watch out for tips on how I use CodeSmith to help me get my projects done…

A buddy of mine pointed me to a great article on writing cool CodeSmith templates:
http://msdn.microsoft.com/library/en-us/dnhcvs04/html/vs04e5.asp

The author does a great job of covering the basics, and then gets into more complicated issues such as sub templates and custom property editors (like for picking a file using an OpenFile dialog box instead of requiring the user to type in the path to a file).

Very cool read.

with 0 Comments