Overwriting variables in t4

203 views Asked by At

I have a structure of 3 layers of inheritance of t4 templates I'm using to generate configs. The goal is to generate web.configs

Global.tt (to be added to every config file):

<customErrors mode="<#= CustomErrors#>
<#+ string CustomErrors = "On"; #> // Set a default value ✓

EnvironmentSpecific.TT can then override this value:

<#@include file="..\Global.tt" #>
<# CustomErrors = "Off"; #> //Override the default value ✓

Up to this point everything works fine

ServerSpecific.TT

<#@include file="..\EnvironmentSpecific.tt" #>
<# CustomErrors = "On"; #> // Does not override ✕

Problem: ServerSpecific.config will have CustomErrors off as it won't override variables defined in the parent.

If I only want to override this value for 1 server without touching the rest of the environment, the only solution I have at the moment is to remove the override(CustomErrors = "On") from the EnvironmentSpecific.TT and add it (CustomErrors = "Off/On") to all 20 ServerSpecific.TT

It is very frustrating and feels like there should be a simple solution

0

There are 0 answers