views:

288

answers:

9

I'm looking for a tool that can do scripted code generation for me on the .NET platform.

+1  A: 

I used CodeSmith and it works well. It is a templating engine with C# scripting as its backend.

Marcel Gosselin
+3  A: 

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.

Program.X
+10  A: 

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.

Pierre-Alain Vigeant
"It look like ASP.NET markup but instead of generating a webpage, it generate C# code." It's a general text transformation tool. It's not really restricted to any specific type of output file.
Mehrdad Afshari
wow, that was incredibly sweet + efficient, exactly what I was looking for.
thr
@Megrdad, like ASP.NET it can be using with C# or VB.NET, but the OP used the C# tag, so I used his language.
Pierre-Alain Vigeant
+1  A: 

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.

David Schmitt
+3  A: 

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.

Daren Thomas
A: 

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.

AlexD
A: 

I'll throw in another one - Reegenerator (www.reegenerator.com)

Randy Minder
A: 

You've already got some good answers, but Ive always found MyGeneration to be the easiest to setup and use.

Sumit