0

Is there a way to retrieve the commands issued by msbuild without actually running msbuild?

Visual Studio manages to do it somehow (Project properties -> C/C++ -> Command Line), but I need to retrieve that information programatically (to feed it to clang, fyi).

I would be happy with either a command line solution a la "msbuild /givemeyourcommandswithoutactuallyrunningthem" or an add-in solution within Visual Studio.

If there is no direct way, I guess the best solution would be to write a tool that parses the (preprocessed) project file and translates the human-readable options to compiler options, e.g.

<PreprocessorDefinitions>WIN32</PreprocessorDefinitions>

would become

/D "WIN32"

But I'd like to avoid that if possible.

David Zaadstra
  • 111
  • 1
  • 5
  • Create a fake `cl.exe` and echo out the arguments. – leppie Jul 09 '14 at 10:00
  • As far as I can see, msbuild calls cl.exe at the exact location of the VS folder, i.e. I can't intercept it by putting a cl.exe somewhere else and manipulating PATH. So I'd have to mess around in the VS directories? I see issues coming up with that... – David Zaadstra Jul 09 '14 at 10:02
  • Rename `cl.exe` temporarily then – leppie Jul 09 '14 at 10:03
  • That would be a pragmatic solution, but not really suitable for generic use: 1. I'd need admin rights which can be difficult in the company environment. 2. cl.exe might be running already. 3. If for some reason my "extraction process" crashes, I'll be left behind with the wrong cl.exe – David Zaadstra Jul 09 '14 at 10:11
  • You can dig it out of the cl.command.*.tlog file. There's another one for the linker. – Hans Passant Jul 09 '14 at 10:23
  • duplicate http://stackoverflow.com/questions/20898409/how-can-i-capture-the-cl-exe-command-line-in-visual-studio-2010 – stijn Jul 09 '14 at 10:59
  • tlog looks great, thanks. I tested how it gets updated, and even with a partial build, all cpp files stay in there, with the last built getting moved to the end. So for a tool to use the tlog file, I would check if the tlog is older than the vcxproj. If yes, do a regular build, and it will be fine. – David Zaadstra Jul 09 '14 at 11:42

0 Answers0