I have a T4 template that is used with the TextTemplatingFilePreprocessor to generate a class that I can then use to generate the output of the template.
At the start of the T4 template I import several namespaces. E.g.
<#@ import namespace="Company.ProductX.Widgets" #>
<#@ import namespace="Company.ProductX.Services" #>
//...
I'd like to use Preprocessor Directives to switch out these imports with another set of namespaces (which provide the same interfaces but differing functionality to ProductX). E.g.
<#
#if(ProductX)
{
#>
<#@ import namespace="Company.ProductX.Widgets" #>
<#@ import namespace="Company.ProductX.Services" #>
//...
<#
}
#endif
#>
<#
#if(ProductY)
{
#>
<#@ import namespace="Company.ProductY.Widgets" #>
<#@ import namespace="Company.ProductY.Services" #>
//...
<#
}
#endif
#>
With the above example the imports seem to create the corresponding using statements in the class regardless of the preprocessor directive. E.g.
using Company.ProductX.Widgets
using Company.ProductX.Services
using Company.ProductY.Widgets
using Company.ProductY.Services
Is there another way to use Preprocessors in T4 templates to affect the template itself rather than just the template output?