Get argument value from TextTransform.exe into the template

后端 未结 2 1447
[愿得一人]
[愿得一人] 2021-01-05 04:56

I can\'t found some example how can I use argument -a when I use TextTransform.exe to generate code from templates. In MSDN is following description for argument -a:

相关标签:
2条回答
  • 2021-01-05 05:06

    Text Template Transformation Toolkit(T4) is from Microsoft not very well supported. Only few examples. If you want to know more go to Olegs Sychs blog. T4 is here very deeply explained.

    After of hours to trying to get parameters from TextTransform.exe in my template I found a solution:

    Add hostspecific="true" attribute to template element as follows:

    <#@ template language="C#v3.5" hostspecific="true"#>
    

    Later in template you can call ResolveParameterValue as Oleg mentioned.

    Example:

    <#
    
     string parameterTest = Host.ResolveParameterValue(null, null, "someKey");
     WriteLine(parameterTest);
    
    #>
    

    You call template generator so:

    "C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.2\TextTransform.exe" -a !!someKey!someValue
    

    After generating should be in generated file: 'someValue'

    0 讨论(0)
  • 2021-01-05 05:17

    The -a argument accepts values in the following format:

    <ProcessorName>!<DirectiveID>!<ParameterName>
    

    These are also the parameters of ITextTemplatingEngineHost.ResolveParameterValue method which you need to call in order to get parameter value in template code.

    0 讨论(0)
提交回复
热议问题