外部文件修改时重建T4模板
我正在构建一组 T4 模板,用于从 XML 文件收集数据。当 XML 文件更改时,有什么方法可以强制 Visual Studio 重新生成模板吗?
目前,开发人员必须修改 XML 文件,然后重建每个模板才能获得更改。我的目标是对开发人员完全隐藏 T4 模板,这样他们除了更新 XML 文件之外无需执行任何操作。
其他信息:我们正在使用 Visual Studio 2008 Visual Basic 项目。
I'm building a set of T4 templates that gather their data from an XML file. Is there any way to force Visual Studio to regenerate the templates when the XML file is changed?
Presently, the developers must modify the XML file and then rebuild each template to get the changes. My goal is to hide the T4 templates from the developer altogether so they don't have to do any action other than updating the XML file.
Other information: We're using Visual Studio 2008 Visual Basic projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几个月前我一直在寻找类似的功能,但我发现的所有内容都表明,当另一个文件发生更改时,您无法自动使模板输出无效。 (例如,无法声明模板“依赖于”另一个文件(Makefile 样式)。)
我实际上只是编写了一个自定义 MSBuild 任务来删除所有 T4 输出文件,从而有效地强制重新运行所有模板在每个构建上。这对于您的需求来说可能有点过分了,特别是如果模板需要很长时间才能运行,但也许您可以组合一些东西来检查模板依赖性。
I was looking for a similar capability a few months ago but all I found indicated that you can't invalidate template output automatically when another file is changed. (E.g. There is no way to declare that a template "depends" on another file, Makefile style.)
I wound up actually just writing a custom MSBuild task that deletes all T4 output files, effectively forcing all of the templates to be re-run on every build. This may be overkill for your needs, especially if the templates take a long time to run, but maybe you can hack together something to check template dependencies.
如果您的目标是完全隐藏它们,我会制作一个名为 T4Awesome 的扩展,让您可以做到这一点。我的扩展不是将模板作为解决方案的一部分并在解决方案资源管理器中可见,而是将它们隐藏在单个文件夹中,然后通过自定义工具窗口将它们呈现给 Visual Studio。它支持参数提示,因此您可以消除对 xml 文件的需要。
If your goal is to hide them altogether, I make an extension called T4Awesome that lets you do that. Instead of your templates being part of the solution and visible in the solution explorer, my extension hides them in a single folder, then presents them to Visual Studio via custom tool windows. Its supports parameter prompting so you might be able to remove the need of your xml file.