C++ transform T4 template ignore output file
Asked Answered
W

3

8

I'm using TextTransform.exe to generate multiple C++ files. Since the tool is not supported directly within Visual Studio for C++ projects I call it by command line (inspired by T4 Generating C++ Code).

In order to generate multiple files I use https://github.com/areve/Entity-Framework-T4-Templates/blob/master/src/dev/MultiOutput.tt that's why I don't need the standard output which is normal generated by the tool.

I call TextTransform.exe like:

"C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe"
-out "<what to put here that NO file is generated?>"
C:\Test.tt

I'm using Microsoft Windows. Maybe there is a "hack" to provide any kind of special char which would be accepted by the program but it wouldn't be possible to actually create a file out of it.

Is there a possibility to provide any command which generates NO file when I execute this command?


Update

As mentioned by @ImprobabilityCast using NUL is a way to go. It's not producing any file but the custom build where I run the tt file with is failing with the message:

Performing Custom Build Tools
CUSTOMBUILD : error : FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path.

I reach what I want but it's not so "nice" that the build action is failing.

Whimwham answered 8/12, 2017 at 9:19 Comment(0)
W
0

I've found a satisfing solution for my problem. Since Microsoft Visual Studio allows for custom build tools to enter multiple lines I realized that I can delete the file generated by the TextTransform.exe I don't need.

So the command I put into "Command Line" contains two lines now:

"C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe" -out "%(DefiningProjectDirectory)$(TempOutputFile)" C:\Test.tt
DEL /F "%(DefiningProjectDirectory)$(TempOutputFile)"
  1. The first line is the actual TextTransform call which produces me all the files I want including the output file I don't need but can't stop to be created.
  2. The second line just deletes me the file I don't need.

This command expects a project variable calles "TempOutputFile". In this way I skip any typo's. For example:

<PropertyGroup Label="Globals">
  <TempOutputFile>DoNotCheckin.h</TempOutputFile>
</PropertyGroup>
Whimwham answered 19/1, 2018 at 6:56 Comment(0)
H
6

Not sure why you don't want the files, but...

In linux we have a wonderful thing called /dev/null that is essentially an empty void just for things like this. I did a quick search, and Windows has it's own equivilent: NUL

Thus, the command you want is:

"C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\
TextTransform.exe" -out NUL C:\Test.tt
Hite answered 19/12, 2017 at 6:10 Comment(3)
Thank you for your reply. I'll certainly check that. I don't want the standard file created by the tool since I create multi files within the tt file myself.Whimwham
See my updated question. Maybe you've another idea how to fix that as well.Whimwham
That's a tough one. Maybe there's a different way to do what you're doing.Hite
C
1

No. The way text transformation was built was only thought to produce a single output file. Multi output was a logical evolution for T4 templates but Microsoft has not evolved it for years now.

The code that you're using (as am I) is basically a hack around that. It uses a very ugly way of using the EnvDTE to manipulate the project system that will probably end up not working one of these days when MS decides to rewrite that system (and one could argue that day is coming).

T4-editor, for example, has a slightly different way of achieving the same thing but you can see that the output still produces the "dummy file":

http://t4-editor.tangible-engineering.com/blog/how-to-generate-multiple-output-files-from-a-single-t4-template.html

Camel answered 13/12, 2017 at 18:30 Comment(1)
Thank you for your answer Hugo. I know its not supported and I'm aware of the EnvDTE hack around. I look for a hack around in the hack around ;-)Whimwham
W
0

I've found a satisfing solution for my problem. Since Microsoft Visual Studio allows for custom build tools to enter multiple lines I realized that I can delete the file generated by the TextTransform.exe I don't need.

So the command I put into "Command Line" contains two lines now:

"C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe" -out "%(DefiningProjectDirectory)$(TempOutputFile)" C:\Test.tt
DEL /F "%(DefiningProjectDirectory)$(TempOutputFile)"
  1. The first line is the actual TextTransform call which produces me all the files I want including the output file I don't need but can't stop to be created.
  2. The second line just deletes me the file I don't need.

This command expects a project variable calles "TempOutputFile". In this way I skip any typo's. For example:

<PropertyGroup Label="Globals">
  <TempOutputFile>DoNotCheckin.h</TempOutputFile>
</PropertyGroup>
Whimwham answered 19/1, 2018 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.