Awhile back I created my own code generator, which I affectionately call CodeBuddy and referred to as my Database Explorer and Code Generator for quite some time. I still use it to generate those really boring parts of my application when mostly working with legacy databases and database-driven web applications. It will generate an entire data access layer from an existing Sql Server Database or various business classes, data access objects, stored procedure wrappers, UI web pages, etc. I have created so many templates that I cannot imagine not using a code generator in instances when it is invaluable.
The fact is that when you are working with legacy databases and database-driven web applications and need to generate some pretty generic code, nothing can take the place of a good ol' template-based code generator. Sure there are people who use code generators incorrectly by generating mounds upon mounds of poorly written code that they might not even understand, but let's not spoil the idea of code generation and code generators because of a reckless few!
During the past week I have received a number of requests for the download link of my code generator and am wondering why when you have tools like CodeSmith, which are far more mature, more widely used, better integrated into Visual Studio 2008, and have many templates built by the community. Sure CodeSmith costs money, but if you are serious about code generation and have a paying gig that can actually benefit from its use, it will pay for itself in just a few hours. This is probably true for many of the code generators on the market.
I haven't personally used CodeSmith for quite some time since I have my own, but I thought I would put it through a quick test to see how quickly I could generate something fairly useful without looking at any how-to guides or screencasts. After installing CodeSmith I started Visual Studio 2008 and was hoping to find a CodeSmith menu but had no such luck. I was a bit worried but my first thought was to go to the Tools Menu in Visual Studio 2008 and consult the Add-In Manager only to find a lovely little CodeSmith option in the Tools Menu:

This is brilliant. I then chose to display the CodeSmith Explorer which brings up a number of code generation templates that ship with the product:

The Frameworks for generating what appears to be data access layers using various technologies looks tempting, but let's keep this real and just generate CRUD Stored Procedures for a particular database. I just happen to have good ol' Northwind on my test machine so I add it quickly as a datasource, pick the AllStoredProcedures Template, run it against Nortwhind and in about 15 seconds get numerous stored procedure for all tables in Northwind:

I didn't mess around with the template options which may take a bit of toying with to get just right, but for a code generator that I don't often use- CodeSmith is pretty darn intuitive to help generate code. I literally finished this process in under 5 minutes easily. Obviously it will take a bit more effort to create my own templates, but that is why it is invaluable to have so many pre-written templates to copy from ;)
I am not suggesting you run out an buy CodeSmith, especially since they have a 30 day trial, but if you are in the position of benefiting from code generation, a template-based code generator that is continually developed and supported by a vendor would be far more valuable than one I essentially use for my personal needs, even if CodeBuddy does rock if I say so myself ;)
You can learn more about CodeSmith here.
Over the past I have mentioned several Code Generators and O/R Mappers for .NET.
Code Generation Tutorials