Can you process T4 templates from inside a .NET application? Is that code available to be called? included in a project? licensing?
update: so it does look like you would have to use VS in some way.
Can you process T4 templates from inside a .NET application? Is that code available to be called? included in a project? licensing?
update: so it does look like you would have to use VS in some way.
As I understand it, T4 is a part of visual studio and cannot be redistributed without it. At the minimum, you will need to redistribute VS shell with your application.
T4 is unfortunately tied to Visual Studio at the moment. I believe Clarius are working on a CodeGen version of their tools which may support automation, but they haven't finalised a feature set yet, plus it's going to be a commercial product. (More info: http://www.visualt4.com/features.html.) Until then, you'll have to either use classic codegen techniques (effectively writing your own T4), or go down the Visual Studio Shell + SDK route which Oleg mentions (more info: http://msdn.microsoft.com/en-us/vsx2008/products/bb933751.aspx).
If you don't have to use the T4 syntax, then the CodeSmith product may do what you require. It includes an API for writing templates and generating code from them. It's a well-respected commercial product, but I haven't used it myself. There's an online help guide, and the API reference is here: http://www.codesmithtools.com/help/Default.aspx##CodeSmith.chm/Using_the_CodeSmith_API.html.
I hope this helps. Best of luck!
I wrote a cleanly reverse-engineered implementation of a T4 engine for the MonoDevelop IDE. It's open-source, licensed under the permissive MIT/X11 license, so you are free to embed the engine in your app or redistribute it. There's also an implementation of the TextTransform.exe command-line tool, and some APIs in the Mono.TextTemplating namespace to aid in hosting the engine.
The only real missing feature right now is custom directive processors - but patches for this are welcome :-)
You can get the code from monodevelop/main/src/addins/TextTemplating in Mono SVN.
Hi tyndall
For processing T4 templates you have to use Microsoft.VisualStudio.TextTemplating.dll but I don't think that you could redistribute this assembly
Regards Muse VSExtensions