Reputation: 408
I need to pass the parameter from my prebuild event to my T4 template. Currently i am using following Pre-build command to build my T4 template file but i am not able to pass parameter to it.
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\texttransform.exe" "$(ProjectDir)VersionGenerator.tt"
I need to pass the parameter to my VersionGenerator.tt template.
Upvotes: 5
Views: 1708
Reputation: 125187
Using TextTransform.exe
there's a command-line switch for passing parameters to t4 templates: -a
which accept parameters in the following format:
-a [processorName]![directiveName]!<parameterName>!<parameterValue>
When using, consider:
Host.ResolveParameterValue
.-a
switch.""
around switch value.Example
Assuming you have the following template Template1.tt
:
<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<# string param1 = this.Host.ResolveParameterValue("", "", "param1"); #>
param1 : <#= param1 #>
The following command:
texttransform.exe "Template1.tt" -a "!!param1!value1"
Results in:
param1 : value1
What should be Pre-build event command line?
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\texttransform.exe" "$(ProjectDir)Template1.tt" -a "!!param1!value1"
Want more parameters?
Just define them in template and pass them usinganother -a
switch:
texttransform.exe "Template1.tt" -a "!!param1!value1" -a "!!param2!value2"
Upvotes: 5