Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get argument value from TextTransform.exe into the template

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:

"Specifies a parameter that a directive processor can query for as a name/value pair. The directive processor and identifier are optional. This allows parameters to be specified for any directive processor or any instance of a particular directive processor."

I need some set of arguments like connection string and so on in my template. My idea was to get a path to configuration file with help of argument -a.

Regards Anton Kalcik

UPDATE: To be clear enough, I want read parameters direct in template.

like image 850
Anton Kalcik Avatar asked Aug 03 '09 10:08

Anton Kalcik


People also ask

What is TextTransform EXE?

TextTransform.exe is a command-line tool that you can use to transform a text template. When you call TextTransform.exe, you specify the name of a text template file as an argument. TextTransform.exe calls the text transformation engine and processes the text template.

What is Texttemplatingfilegenerator?

TT stands for - Visual Studio Text Template is a software development tool created by the Microsoft. Further explanation - TT file contains text block and control logic used for generating new files. To write the Text Template file we can use either - Visual C# or Visual Basic Code.


1 Answers

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'

like image 179
Anton Kalcik Avatar answered Oct 19 '22 00:10

Anton Kalcik