获取Visual Studio在每个版本上运行T4模板 [英] Get Visual Studio to run a T4 Template on every build
问题描述
如何获取T4模板以在每次构建时生成其输出?现在,它仅在我对模板进行更改时才重新生成.
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 questions similar to this:
在Visual Studio中进行T4转换和构建顺序(未回答)
如何在可视化环境中构建t4文件工作室?(答案不够详细(尽管仍然很复杂),甚至没有任何意义)
How to get t4 files to build in visual studio? (answers are not detailed enough [while still being plenty complicated] and don't even make total sense)
必须要有一种更简单的方法!
There has got to be a simpler way to do this!
推荐答案
我使用JoelFan的答案来解决这个问题.我更喜欢它,因为您不必记住每次将新的.tt文件添加到项目时都需要修改预构建事件.
I used JoelFan's answer to come up w/ this. I like it better because you don't have to remember to modify the pre-build event every time you add a new .tt file to the project.
- 将TextTransform.exe添加到您的
%PATH%
- 创建了一个名为transform_all.bat的批处理文件(见下文)
- 创建预构建事件"
transform_all ..\..
"
- add TextTransform.exe to your
%PATH%
- created a batch file named transform_all.bat (see below)
- create a pre-build event "
transform_all ..\..
"
transform_all.bat
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: set the working dir (default to current dir)
set wdir=%cd%
if not (%1)==() set wdir=%1
:: set the file extension (default to vb)
set extension=vb
if not (%2)==() set extension=%2
echo executing transform_all from %wdir%
:: create a list of all the T4 templates in the working dir
dir %wdir%\*.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 file_name=%%d
set file_name=!file_name:~0,-3!.%extension%
echo: \--^> !file_name!
TextTransform.exe -out !file_name! %%d
)
echo transformation complete
这篇关于获取Visual Studio在每个版本上运行T4模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!