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 Friday, August 6, 2010 by | Add Comment

New Comment

Your Name:
Email (for internal use only):
Comment:
 
Code above:

Categories

Recent Tweets

  • Simon Ince's Blog: Hierarchies with HierarchyID in SQL 2008 http://t.co/xSDwiF6rRS.
  • Visual Studio 2010 WAS painfully slow - CodeProject http://t.co/Usba1x6CZy

Valid HTML5