Get Visual Studio to run a T4 Template on every build

后端 未结 22 2451
余生分开走
余生分开走 2020-11-22 08:29

How do I get a T4 template to generate its output on every build? As it is now, it only regenerates it when I make a change to the template.

I have found other ques

22条回答
  •  逝去的感伤
    2020-11-22 09:01

    The pre-build can be reduced to a single line:

    forfiles /p "$(ProjectDir)." /m "*.tt" /s /c "cmd /c echo Transforming @path && \"%CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\1.2\TextTransform.exe\" @file"
    

    This transforms all .tt files in the project and lists them to the build output.

    If you don't want the build output then you have to work around some "interesting behaviour":

    forfiles /p "$(ProjectDir)." /m "*.tt" /s /c "cmd /c @\"%CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\1.2\TextTransform.exe\" @file"
    

    Of course, you can pull this out into a batch file to which you pass the project directory path if you wish.

    NB The path may require some tweaking. The path above is where VS 2008 installed it on my machine; but you might find that the version number between TextTemplating and TextTransform.exe is different.

提交回复
热议问题