I'm looking for a tool that can do scripted code generation for me on the .NET platform.
I used CodeSmith and it works well. It is a templating engine with C# scripting as its backend.
CodeSmith has an excellent ASP-style editor syntax and a community around it providing all the major frameworks.
http://www.codesmithtools.com/
It can be command line driven, too.
Have a look at the T4 Text Template tool that is built-in Visual Studio.
It look like ASP.NET markup but instead of generating a webpage, it generate C# code.
I use an open source implementation of a syntax very similar to T4: Template Based Code Generator by Rudi Breedenraedt. It has proven stable and flexible.
Scott Hanselman has a nice introductory blog entry on T4 (mentioned in other answers):
T4 is a code generator built right into Visual Studio. To be clear, you HAVE THIS NOW on your system…go play
(quote from the blog entry)
Also, he lists some tools you might like to look at to make editing these templates easier.
I'd recommend TemplateMaschine in addition to mentioned tools - it works quite well for our project. Templates also use ASP.NET-like syntax and it's free and open source.
You've already got some good answers, but Ive always found MyGeneration to be the easiest to setup and use.