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.
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
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
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)"
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.
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>
Related
While trying to setup the Cap'n Proto compiler as a custom build tool in Visual Studio 2017, I came across a curious behavior, it only seems to work when called directly and not through a batch file.
What I first tried was, for each .capnp file, set the following Custom Build Tool settings:
Command line: "$(SolutionDir)run_capnpn.bat" compile -oc++ "%(FullPath)"
Description: Executing capnp.exe on %(Identity)...
Outputs: %(Identity).c++;%(Identity).h
I made the batch file because I wanted to avoid polluting my %PATH% with the capnp folder, this is what it contains:
#echo on
echo %*
SET PATH=%PATH%;C:\GitHub\capnproto\bin\c++\src\capnp\Debug
start /wait "" capnp.exe %*
exit /b %errorlevel%
However, with this setup the Custom Build Tool was only called on 1 of the 5 capnp files in my solution (all 5 files had exactly the same settings). I know this because only one pair of generated files appeared and only one message appeared in my build log.
Even weirder, if I compiled again it would do the next file, and on the following compile it would do another file. In all, it would take 5 compiles (one per file) before it considered everything to be fully built and stop calling the custom build tool.
After much trial and error and some help from other programmers on Discord, I tried adding capnp.exe to my path and call it directly (instead of going through the batch file) so for each capnp fil I changed the command line setting to:
capnp.exe compile -oc++ "%(FullPath)"
and now it all builds correctly. Is it possible to call a custom build tool through a batch file? and if so how?
I have a project, which use a .rules file to build some non-c++ sources. How to make MSBuild print diagnostic output from this tool? -- Precisely cerr stream.
(I silently presume, the M$ team have not reached that level of insanity, to give the custom building tools functionality without possibility to print errors from them.)
I've actually noticed you marked question with label visual-studio-2008. I guess it means your custom build tool processes non cpp files in vc2008 project? If so, I think it is not built by msbuild but with vcbuild.
In this case try to add echo on in front of command executed by custom tool.
Vcbuild creates batch files in %temp% that first line contains #echo off and then it is executed. So if you add echo on you should see complete output in output window including command line used for command execution.
I am debugging c++ console application with Visual studio. I exhausted of inserting the same input every time I debug this program. I would like to use the same input more times.
I do this without debugging in command line with command: Program.exe < 1.in
Is it possible to use debugging with standard input redirected from file???
I already tried looking in to procejt properties. I tried setting Command to $(TargetPath) < 1.in instead of $(TargetPath).
I also tried setting Command Arguments to < 1.in. Niether of these method worked.
I am using Visual Studio 2012. But this is probably same in all versions of studio.
This is a supported debugging scenario. You do have to make sure that the debugger can find the file. Leave the Command setting at $(TargetPath). A possible value for the Command Arguments setting is:
< "$(ProjectDir)test.txt"
if the input file "test.txt" is located in the project directory. Or type the full path of the file to be sure. The MSDN article that describes this feature is available here.
I just create a file called stdin.txt in the project
1) set the Build Action to Content
2) Copy to Ouput Directory: Copy if newer
Then when you build stdin.txt is copied to the same folder as the executable.
Then in project properties debug|command line arguements enter the following
< stdin.txt
There is no need to use a path macro
If you don't want to mess with the the path you can add a new file with a right click on the source files folder in the solution explorer and then paste to it the content from the wanted file. And then change the command argument to the new file name.
I currently use the following cleartool command using Visual Studios External tool interface:
Command: \installationpath\cleartool.exe
Arguments: annotate -nheader $(ItemPath)
Initial directory: $(ItemDir)
I do use the output window. Which will let that command print out the location of the .ann file it produces. I'm wondering if there is a way for Visual studio to auto open that produced file?
In this case its not a huge hardship to copy the location and open the file. I'm just always looking for ways to make things easier.
Using just one external tool, you wouldn't be able to execute cleartool, and to open a file (generated from the cleartool command).
You can open a file from a Visual Studio External Tool as explained here, but that wouldn't execute cleartool.
So I would recommend executing a script (.bat, .cmd, .vbs) in order to:
do the cleartool command you want
open the generated file.
You would pass to this script no only $(ItemPath), but also, depending on where it is generated, $(ItemDir), or $(ProjectDir), or $(SolutionDir), or $(TargetDir).
I realize this is going to be an exotic question, but I just can't find the answer.
I'm trying to fix up and enhance an old visual basic-based application.
My problem is: where is the output directory with the compiled binaries?
Thanks.
If some clarification is needed, please ask.
In the .VBP, if there is a line specifying the path like this
Path32="C:\"
Then the resulting EXE will be built at that location. Otherwise, it will be built in the same directory as the .VBP file. The path can be relational as well and may not be a fully qualified path.
I think you want the /outdir switch. This overrides the Path32 setting in the Project file.
VB6[.EXE] [[{/run | /r}] | [/runexit] | [{/make | /m}] projectname]
[/out filename] [/outdir path] [/d const=value{[:constN=valueN]}]
[/mdi | /sdi] [{/cmd argument | /c argument}]
Options:
/run or /r projectname Tells Visual Basic to compile projectname and run it,
using the arguments stored in the Command Line
Arguments field of the Make tab of the Project
Properties dialog box.
/runexit projectname Tells Visual Basic to compile projectname and run it.
Visual Basic will exit when the project returns to
design mode.
/make or /m projectname Tells Visual Basic to compile projectname and make an
executable file from it, using the existing settings
stored in the project file.
/out filename Specifies a file to receive errors when you build using
/m or /runexit. If you do not use /out, command line
bild errors are displayed in a message box.
/outdir path Specifies a directory path to place all output files in
when using /make. This path must already exist.
/d or /D const=value... Tells Visual Basic which values to use for conditional
compilation constants when making an .EXE or ActiveX
component with the /make switch. Separate multiple
constants with colons.
/cmd or /c argument Specifies a command string to be passed to the Command$
function. When used, it must be the last switch on the
command line.
/mdi or /sdi Changes the Visual Basic environment to either Single
Document Interface (SDI) or Multiple Document Interface
(MDI) mode. Visual Basic remains in this mode until
you change it.
/? Displays a list of valid command line switches.
You may use a group name in place of projectname in any of the above switches.
Works fine here.
There is no equivalent 'bin/lib' output directory for VB6. When you compile a VB6 project, the default is to compile to the same folder as the project (vbp file). It is also possible to compile to any other folder available to the user.