How can one create more than one file from a T4 generator or template?

Aug 5, 2009 at 5:46 PM

All --

How can one create more than one file from a T4 generator or template?

The long story is as follows.

(I hope I have my T4 terminology straight here; but, I apologize ahead of time in case I do not. Regardless, you will, I am sure, get the gist.)

I have a reusable T4 generator-file.

I create a consuming T4 template-file for each table I want to generate for, set a few properties in it, and I am done.

Done. Every place I put a template-file, I get an output CS file that has the code I want. Nice.

However, what I would rather do (maybe) is to somehow start the generation process and loop through all table names in the given database and create an output file for all tables that are "code tables", maybe identifiying a "code table" by matching rules for a particular schema/suffix/prefix/etc.

Maybe this is too much bookkeeping. It should flag orphaned output files if the table no longer exists. Etc. But, maybe it would be nice.

Whatever, the crux of the matter, however, is that 1 generator-file (or perhaps one generator-file and one template-file) would need to produce >1 output file.

(It looks like Clarius http://www.visualt4.com/downloads.html may have this already or soon have it; but, I am wondering if there is any way to do it the poor-man's way, with the out-of-the-box T4.)

What do you think?

Please advise.

Thank you.

-- Mark Kamoski

Coordinator
Aug 5, 2009 at 7:15 PM

Here is how T4 Toolbox solves this problem today: http://www.olegsych.com/2008/09/t4-tutorial-creating-complex-code-generators/

Aug 6, 2009 at 3:23 PM
olegsych wrote:

Here is how T4 Toolbox solves this problem today: http://www.olegsych.com/2008/09/t4-tutorial-creating-complex-code-generators/

Oleg --

That is NICE.

It works like a charm.

There is one thing. This is a small thing. There is an extra- file created by this approach. The extra-file in this example is "NorthwindProcedures.txt". Is there a way to supress the creation of this extra-file?

Please advise.

Thank you.

-- Mark Kamoski

Coordinator
Aug 6, 2009 at 7:11 PM

Not that I know of. Visual Studio will generate it no matter what. The best workaround I found is to generate something useful in this file.