Running TextTransform.exe (T4) on a build server
Asked Answered
V

3

10

I am trying to setup a process where my T4 templates will be transformed on the build server (Visual Studio is not installed there).

I've read all online references, but could not get a clear source that shows how to do this.

Specifically, here's the 2 issues i've encountered:

  • TextTransform.exe throws an error about missing DLL:

C:\TeamCity\buildAgent\work\AppSettings.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'Microsoft.VisualStudio.TextTemplating.Interfaces.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found

Registering the DLL files using gacutil fixes this issue, although i would like to avoid this step.

  • Using the Host.ResolvePath(string) method does not return any value when being run outside of Visual Studio.

This method helps in determining a full path to the .txt file that is used by the template as its data source. Without it this file can not be found on the build server.

Any help will be appreciated in getting this running.

EDIT: opened an MS CONNECT issue: https://connect.microsoft.com/VisualStudio/feedback/details/744137/texttransform-exe-does-not-work-without-vs2010-installed

References i have checked:

Vachill answered 24/5, 2012 at 12:14 Comment(3)
I am going to raise an issue on MS Connect as their article on MSDN (Last item on the references i posted) seems outdated and does not work properly.Vachill
Any progress on this? We still get the exact exception on a server with no VS installed even though all the TextTransform assemblies are in GAC.Dragoman
You have to install the assemblies into GAC. I had the same issue.Obcordate
K
2

I believe the issue is that you are using host specific features such ResolvePath.

One way I would try is making sure the templates doesn't use ResolvePath but instead rely on relative paths from a well-known location.

This well-known location could be known by:

1. Convention
2. Environment variable
3. Registry
4. SQL Server
5. Web Service
6. And others

If you don't like the idea of forcing devs setup environment variables I would consider making a "smart" resolvepath that uses the environment variable if available, otherwise relies on Host.ResolvePath.

Hope this helps

Knobby answered 24/5, 2012 at 18:8 Comment(1)
For my simple scenario, it would suffice to be able to resolve the template (.tt file) full path. The input file will be usually placed next to it, or under a path relative to it.Vachill
S
1

Ditch the Microsoft TextTransform.exe and use the free one that ships with MonoDevelop that doesn't have external dependencies.

See here: T4 without Visual Studio?

Slowworm answered 25/5, 2012 at 18:15 Comment(0)
A
0
  1. Copy the following directory from your development machine to the build server.

    Source (your machine):

    %CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\<version>.0

    Destination (build server):

    %CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\<version>.0

    Where <version> is the most recent version.

  2. Copy all assemblies (.dll) from your development machine to the build server.

    Source (your machine): %WinDir%\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.*

    Destination (build server):

    %CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\<version>.0

    Where * is the rest of the directory name.

  3. Using Gacutil /i install all copied assemblies into GAC of the build server.

Anthropocentric answered 18/3, 2015 at 5:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.