Larkware banner
border

Review: CodeSmith 4.0

CodeSmith 4.0, starting at $99
CodeSmith Tools, LLC
Dallas, Texas
(214) 420-1330
https://www.codesmithtools.com/

CodeSmith is a template-based code generator that can produce code for any text-based language: C#, Visual Basic .NET, FORTRAN, T-SQL, whatever; as long as it's text, CodeSmith can output it. CodeSmith's template syntax is based on ASP.NET, so it's easy to pick up for most .NET developers. It comes with two different GUIs: CodeSmith Explorer, which provides a simple way to launch templates and generate code, and CodeSmith Studio, which is a full-blown IDE for template development, featuring IntelliSense-like statement completion, color-coding, incremental search, outlining, tabbed windows, and all the other goodies you'd expect from an IDE. There's also a console version that you can easily integrate into your own build process, MSBuild integration, flexible strategies for merging generated code with custom code, an API for integration with relational data sources, and the ability to hook up your own custom metadata sources.

Version 4.0 strengthens the integration of CodeSmith with Visual Studio 2005 through the introduction of CodeSmith Projects and ActiveSnippets. CodeSmith Projects can be used in many contexts (from Windows Explorer, the command line, MSBuild, and CodeSmith Explorer, for example), but regardless of the context they let you manage an entire code generation process by grouping related CodeSmith templates together. When used from within Visual Studio, you can set a CodeSmith Project to automatically regenerate its output when you build the containing Visual Studio project, thus hooking the code generation process directly into your build process. ActiveSnippets are like Visual Studio Code Snippets but made actually useful by having access to all of CodeSmith's code generation facilities and metadata; think of them as inline code generators that you can access with a few keystrokes any time you like.

Advanced capabilities you'll find in CodeSmith include the ability to separate scripting logic from template code by putting it in a code-behind file, calling into sub-templates, compiling templates into assemblies for programmatic execution, support for dealing directly with XML files, active code generation via merge strategies, and the ability to define a property of any .NET type and with a custom editor for data input. You can create multiple output files from a single template and execute SQL scripts directly after generating them. New features in version 4.0 include easy data mapping (ideal when you want to map types from one language to another), many enhanced templates, and property value persistence across CodeSmith sessions.

You'll find two broad types of code generators out there. Some concentrate on taking a database or an XML schema and building up an application from it, aiming to do most of the work of bringing your data to a Web or a Windows interface. CodeSmith is the other type: a general-purpose tool that can generate pretty much anything you can think of. You'll need to spend some time learning how to use it (and plan on spending some of that time online, because the documentation with the application is very sketchy). But once you understand how all the pieces fit together, you can use it anywhere that you spot patterns in your code, whether that code is SQL to generate repetitive stored procedures or classes that you use to hook up routine sorts of objects over and over again. I find it a great tool to have handy for all sorts of utility coding purposes.

CodeSmith 4.0 comes in two different versions. You can download a 30-day trial that includes all of the features, after which you need to make a choice. The $99 CodeSmith Standard gives you most of the CodeSmith features, the console client, and the basic CodeSmith Explorer GUI client. The $399 CodeSmith Professional adds the CodeSmith Studio IDE, Visual Studio .NET integration, and a few other advanced features. Either way, you get a batch of sample templates, and you'll find a lot more user-contributed templates on the CodeSmith support Web site.

Full disclosure: I have a past contractual relationship with CodeSmith Tools, LLC, having written the help file for a previous version of the product. I have no financial interest in version 4.0 and I was a happy CodeSmith user before that opportunity came along.

CodeSmith screenshot  Click for larger screenshot 

Mike GunderloyLarkware is the editor of Larkware, the daily .NET newspaper of record.

Published December 28, 2006