2

I'm working with t4 templates and faced with following problem. I need include another existing t4 template to my template. But I have one restriction: name of included t4 template file is generated dynamically. I used include directive for this, but it doesn't work.

<#@ include file="\Helpers\<# FileName.tt#>" #>

I get an error:

 An unexpected start or end tag was found within a block. Make sure that you did not mis-type a start or end tag, and that you do not have any nested blocks in the template.

Value of property FileName is generated dynamically

Mykhalik
  • 244
  • 1
  • 4
  • 14

1 Answers1

0

In order to use a parameter, you need to setup msbuild property (say in the BeforeBuild target) or pass to msbuild as /p:TargetPath="[path]", and you can use them with the following:

<#@ include file="$(TargetPath)\TargetFile.tt" #>

(more information on MSBuild properties usage here)

Additionally, you can configure t4 templates to run on each build

<!-- This line could already present in file. If it is so just skip it  -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- process *.tt templates on each build  -->
<PropertyGroup>
    <TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />

... as mentioned here: Get Visual Studio to run a T4 Template on every build

Community
  • 1
  • 1
webbexpert
  • 704
  • 9
  • 15