I am using T4toolbox to generate a bunch of files, let's say my t4 file name is x.t4, but default it generate a x.txt, which has nothing inside, can I tell t4 engine not to do this?
-
You're only telling what shouldn't happen,not what should happen. What's the expected output? – Sander Rijken Apr 08 '10 at 15:32
-
my expected output is not to output the default output. Let's say my x.t4 by default generate f1.cs , f2.cs, and x.txt, now I want to output f1.cs, f2.cs only, because x.txt is empty, of no value at all. But I don't know how to get rid of the x.txt. – Fred Yang Apr 08 '10 at 15:58
3 Answers
Found a trick/hack!
<#@ output extension="/" #>
or
<#@ output extension="\\" #>
Visual Studio neither outputs the default file nor complains about its inability too much.
If you want to avoid warnings, you can also modify output path through the extension:
<#@ output extension="xml/../_" #>
The file will still be created and attached to the T4 file within the project hierarchy in Visual Studio, but you can put it into any directory.
P.S. I've tried it with T4MultiFile NuGet package, but it should work with T4Toolbox too, I think.

- 33,702
- 16
- 105
- 146
-
1Good one. Unfortunately you still get a warning about the output file name being invalid. – Oleg Sych Dec 20 '12 at 01:42
-
@OlegSych At least it's not an error. :) "Extensions" like `"xml/../1.txt"` and even `"xml/../../../1.txt"` work too; the file is created, but it can be placed anywhere in the project (it's still "attached" to the TT file in the Solution Explorer). – Athari Dec 20 '12 at 12:30
-
This doesn't work. This indeed removes the file, but also prefents (re)generating the files based on the template – hvk May 28 '16 at 08:47
-
-
@Discord, I use VS2015 on Win 10, I've tried it in several projects like Class libraries and WCF projects. T4 Toolbox is installed – hvk May 30 '16 at 19:14
-
1This works for me when generating files in .net projects (e.g. class library). Unfortunately this hack crashes Visual Studio when used inside a SQL project (sqlproj) :( – Yodan Tauber Jun 08 '20 at 08:00
Right click on x.t4 in Solution Explorer and click Properties. It will say "TextTemplatingFileGenerator" beside Custom Tool. Delete this.
x.t4 will now be part of your project but it will not generate anything. This is useful when the .t4/.tt file is only being used as an include file in other templates.

- 2,449
- 3
- 27
- 33
-
14It should not be marked as answer. The question was how to ignore output empty blank file, not how to avoid T4 to be run at all. You might need T4 to be run to generate set of separate files (i.e. you use MultipleOutputHelper.ttinclude), but you do not want this empty file to be generated along with it. Athari provided the right answer – YMC May 06 '15 at 22:57
-
2I create a file for every enum, class, interface that has a specific attribute to convert .net definitions to TypeScript files. It could potentially create hundreds of files. I don't want the default output file. That's why this is not the answer. – Brain2000 Aug 16 '19 at 05:35
No. This file is created by Visual Studio and not by T4. The best you can do is generate something useful in it such as actual code or, perhaps, a log of the code generation run.

- 6,548
- 36
- 34
-
1Thanks. This has been my observation too, but how does T4MVC accomplish it? Running T4MVC.tt does not seem to produce a T4MVC.* file. – Emmett Apr 02 '12 at 20:13
-
@Oleg Sych MSFT I ask a related question here: http://stackoverflow.com/questions/13838142/put-all-methods-in-one-tt-file-and-use-it-in-another-t4-files-in-codetemplates would you please check it. – Saeid Dec 12 '12 at 11:34