This project is read-only.

Run from TextTransform.exe command line tool.

Feb 4, 2009 at 2:48 PM

I’ve a question for T4 toolbox template. When I run a .tt file from VS there is not a error, but when I run the .tt file from command line, I’ve the follow exception:

The following Exception was thrown:
System.InvalidCastException: Unable to cast object of type ‘Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost’ to type ‘System.IServiceProvider’

The exception was throw in the next code line:

IServiceProvider hostServiceProvider = (IServiceProvider)TransformationContext.Host;

T4 toolbox by architecture cant run from TextTransform.exe command line?

Mar 31, 2009 at 11:46 AM
We add a new .tt file called VisualStudioContext that let to run from both VisualStudio IDE and TextTransform.exe command line.

Here is a little sample:

<#@ include file="T4Toolbox.tt" #>
<#@ include file="T4Toolbox\VisualStudioContext.tt" #>
<#@ include file="T4Toolbox\MyCodeGenerator.tt" #>
<#
                VisualStudioContext.OpenSolution(solutionRootPath + solutionName + ".sln");
                MyCodeGenerator generator = new MyCodeGenerator();
                // …
                generator.Run();
#>

From command line:
c:\MyProject\"c:\Archivos de programa\Archivos comunes\Microsoft Shared\TextTemplating\1.2\TextTransform.exe" -I "c:\Archivos de programa\T4 Toolbox" MyGeneratorCommand.tt
Apr 8, 2009 at 12:37 PM
Thanks for implementing and sharing this, Marcos. We are discussing additional options for supporting TextTransform.exe in T4 Toolbox: http://t4toolbox.codeplex.com/Thread/View.aspx?ThreadId=52069. Please join the discussion if you are interested.

Thanks,
Oleg
Aug 26, 2009 at 4:47 AM

Hi ,

I have a Mainfile.tt which just prints hello world, it runs fine from visual studio but i am not able to run it through command prompt. I used below command deom command prompt.

C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.0>TextTransform -I "D:\I-deal\TFS\code\IPAD_POC\Ipad_2008\IPAD\EntityGenerator\MainFile.tt" -out "d:\Sample.txt"

 

It neither gives any error nor any success..

Am i missing any thing. Please suggest.

Aug 26, 2009 at 1:52 PM

Hi prasadrmarathe,

 

maybe you must to use -I parameterm like:

 

c:\MyProject\"c:\Archivos de programa\Archivos comunes\Microsoft Shared\TextTemplating\1.2\TextTransform.exe" -I "c:\Archivos de programa\T4 Toolbox" MyGeneratorCommand.tt

 

Best

Jul 5, 2012 at 6:05 PM

@lagear,

Where is the VisualStudioContext.tt file? Also MyCodeGenerator.tt? 

I'm looking to execute the tranform from the command line as well; doesn't seem to be any good solution to this issue.

Thanks in advance!!!!

-Tim