tangible T4 Directives

 

The tangible T4 Editor extends the set of existing T4 Directives that can be used inside T4 Text Template files. This list gives an overview on additional directives that can be used when working with the tangible T4 Editor.

 

The documentation of the basic T4 Text Template Directives is availabl in this MSDN Article.

 

Directive: includeForIntellisenseOnly

 

Purpose

Provides IntelliSense for an include file without actually including it, because that will result in a double include.

 

Background

Including a T4 Text Template in another one using the <#@ include #> directive (see MSDN Article) results in a replacement removing the <#@ include #> statement and pasting the contents of the included file there instead. This might cause a multiple definition of the same methods and variables when the same file is included more than once.

 

In order to use IntelliSense for an include file that has already been included somewhere else, you can use the <#@ includeForIntelliSenseOnly #> directive.

 

Sample

This sample consists of three T4 template files: a .tt-File that includes the reusable template Reuse1.ttinclude. This reusable template includes Reuse2.ttinclude itself. Thus the main .tt-File won’t get IntelliSense and AutoCompletion for the variables declared in Reuse2.ttinclude. With the <#@ includeForIntelliSenseOnly #> directive this issue can be solved.

 

Main.tt


<#@ template hostspecific="false" language="C#" debug="true" #>

<#@ include file="Reuse1.ttinclude" #>

<#@ includeForIntellisenseOnly processor="tangibleT4Editor" file="Reuse2.ttinclude" #>

<#= GetString() #>


 

Reuse1.ttinclude


<#@ intelliSenseLanguage processor="tangibleT4Editor" language="C#" #>
<#@ include file="Reuse2.ttinclude" #>
<#+
  string GetString()
  {
      return String1;
  }
#>


 

Reuse2.ttinclude


<#@ intelliSenseLanguage processor="tangibleT4Editor" language="C#" #>

<#+
  string String1 = "Hello";
  string String2 = "World";
#>