How to regenerate T4 templates from command prompt?
I am using T4 templates for web.config templating for different environments (development, production). You can regenerate templates from Visual Studio, but what if you want to regenerate all of them from console. It is very useful if you had some mass change in all your web.tt (in different projects) and now need to regenerate corresponding web.config-s.
Here is a little batch script that can help you to do this:
@echo off SETLOCAL ENABLEDELAYEDEXPANSION :: set the working dir (default to current dir) set wdir=%cd% if not (%1)==() set wdir=%1 echo executing transform_all from %wdir% :: create a list of all the T4 templates in the working dir dir %wdir%\web*.tt /b /s > t4list.txt echo the following T4 templates will be transformed: type t4list.txt :: transform all the templates for /f %%d in (t4list.txt) do ( set configfile=%%d set configfile=!configfile:~0,-3!.config echo: \--^> !configfile! "%CommonProgramFiles%\Microsoft Shared\TextTemplating\1.2\TextTransform.exe" -out !configfile! %%d ) echo transformation complete
Posted on May 6, 2010 by Viktar Karpach