0

I want to build my .tt file on every build. I found this solution (Get Visual Studio to run a T4 Template on every build, answer by Cheburek) and got it running by following the steps

  1. Install Visual Studio SDK
  2. Install Visual Studio 2010 Modeling and Visualization SDK
  3. Adding the import for Microsoft.TextTemplating.targets and <TransformOnBuild>true</TransformOnBuild> to my .csproj

My problem now is:

I am using the following assembly import in my T4 file:

<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="My.Example.Namespace.Path" #>

I need this because I need to access a class which is defined in the same project. But now (I think because the tt-transformation is the first thing that is done on building) I cannot use this namespace import because the following error occurs on building:

Error   Compiling transformation: Metadata file '$(TargetPath)' could not be found.

The T4-file was working before when it was used "normal" (file generation on saving the T4 file)

Is it somehow possible to execute the T4-transformation (as last build-step) so I can access $(TargetPath) without problems in my T4-file?

Community
  • 1
  • 1
Markus Weninger
  • 11,931
  • 7
  • 64
  • 137

1 Answers1

5

I have had the same problem today and was searching for an answer. The problem is that the dll is not build yet and cannot be loaded. Though it should work if there was already a successfull build in the TargetPath.

The way I got this work was by splitting the code into two projects. The code used in the t4 template is now in the other project.

I had to reference the new project in the original project.
And in the t4 template from the original project I had to change the assembly reference:

<#@ assembly name="$(SolutionDir)newproject\bin\Debug\newproject.dll" #>
Gideon Mulder
  • 344
  • 3
  • 6