Rebuild T4 template when external file is modified
Asked Answered
P

2

7

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.

Pender answered 9/11, 2010 at 21:4 Comment(2)
possible duplicate of Get Visual Studio to run a T4 Template on every buildComfortable
There is a VS Extension for this AutoRunCustomTool.Colorific
L
1

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.

Leftward answered 9/11, 2010 at 21:8 Comment(1)
Where are the T4 output files?Curriery
P
0

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.

Prosthodontist answered 2/2, 2016 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.