tags:

views:

1014

answers:

4

I'm trying to wireup some code gen templates to my team's automated build process. Our SCM team doesn't want Visual Studio on our build machine (which I have a hard time arguing with).

Is there a way to install the T4 engine without Visual Studio?

+3  A: 

I haven't tried it, but I believe you would be able to take the command line tool, drop it on your build server, and transform your templates prior to/during the build.

http://msdn.microsoft.com/en-us/library/bb126461.aspx

mannish
Sweet! I see possibilities...
Robert Harvey
+1  A: 

My understanding is that you would still need to have Visual Studio installed. Why swim against the current though? Have you considered generating code at design time as opposed to build time?

Oleg Sych
+10  A: 

We're not actually generating code... we're generating Sandcastle scripts and we definitely want that done on the build server. We've taken an approach where we've created a series of custom attributes that we decorate our code with that shapes how the doc is generated. So we have a set of .tt files that reflect our assemblies for these attributes, and generates Sandcastle's input file (.shfb). I could have done it with a custom tool, but T4 fit the bill nicely.

Anyway... I've confirmed that you can run TextTransform.exe without Visual Studio. All you need is the Microsoft.VisualStudio.TextTemplating.dll present. I created a fresh VM, installed .NET 3.5, and copied the following to the file system:

  • TextTransform.exe
  • TextTemplate.ico
  • Microsoft.VisualStudio.TextTemplating.dll
  • Test.tt (something I created)

Test.tt looked like this:

<#@ template language="C#3.5" debug="true" hostspecific="true" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Collections"#>
<#@ import namespace="System.Collections.Generic"#>
<#@ import namespace="System.Xml" #>
<#@ output  extension=".cs" #>

Test: <#=System.DateTime.Now.ToString()#>....

From the VM I executed Test.tt like so:

C:\TextTransform.exe Test.tt

and Test.cs was created containing

Test: 6/10/2009 5:33:32 PM....

VICTORY!!!!

The hardest part was finding Microsoft.VisualStudio.TextTemplating.dll. I had to fire up FileMon and execute a template on my box which has Visual Studio. FileMon then told me where TextTransform.exe was loading it from. This can be in several places potentially, but I found it in the GAC at C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.dll. In order to browse to that location using Windows Explorer, I had to create a subst like so:

subst X: C:\Windows\assembly

then I could browse to X:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating\9.0.0.0__b03f5f7f11d50a3a\ and copy the dll.

Anyway... thanks for the idea mannish. Hopefully this helps some other poor soul someday :)

kellyb
+2  A: 

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 providers - but patches for this are welcome :-)

You can get the code from monodevelop/main/src/addins/TextTemplating in Mono SVN.

mhutch