让 Visual Studio 在每次构建时运行 T4 模板 [英] Get Visual Studio to run a T4 Template on every build

查看:44
本文介绍了让 Visual Studio 在每次构建时运行 T4 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 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 ...."

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆