[英]How to pass the parameters to T4 templates using pre build event command line
我需要將參數從我的預構建事件傳遞到我的 T4 模板。 目前我正在使用以下預構建命令來構建我的 T4 模板文件,但我無法將參數傳遞給它。
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\texttransform.exe" "$(ProjectDir)VersionGenerator.tt"
我需要將參數傳遞給我的 VersionGenerator.tt 模板。
使用TextTransform.exe
有一個命令行開關用於將參數傳遞給 t4 模板: -a
接受以下格式的參數:
-a [processorName]![directiveName]!<parameterName>!<parameterValue>
使用時,請考慮:
Host.ResolveParameterValue
解析參數。-a
開關。""
。例子
假設您有以下模板Template1.tt
:
<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<# string param1 = this.Host.ResolveParameterValue("", "", "param1"); #>
param1 : <#= param1 #>
以下命令:
texttransform.exe "Template1.tt" -a "!!param1!value1"
結果是:
param1 : value1
什么應該是預構建事件命令行?
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\texttransform.exe" "$(ProjectDir)Template1.tt" -a "!!param1!value1"
想要更多參數?
只需在模板中定義它們並使用另一個-a
開關傳遞它們:
texttransform.exe "Template1.tt" -a "!!param1!value1" -a "!!param2!value2"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.