views:

281

answers:

3

I realize that Visual Studio has the "/P" option to generate preprocessed files, but it's extremely inconvenient. I'm looking for an addin that allows you to right-click on a file and select "view preprocessed" - or any similar solution that would basically preprocess the currently-open file (with the appropriate options from the current configuration) and show me the output, with no extra hassle. Does such a thing exist?

+2  A: 

In the UI, you can configure an "External Tool" (from the tools menu). You can make such a tool that invokes the compiler with the current file and the "/P" option and have the compiler output to the screen. For the external tool, configure it to output to the output window.

jdv
Not the perfect solution, but that may work; however, how do I configure this external tool to use the command line that Visual Studio would use if I were to select "compile file" (and just add /P to it) ?
Virgil
A: 

You compile proc using the same method within C++ project and external build tool. you right click on proC file and if the compiler instruction are set in Custom Build Setup (in MS Visual Studio) it will show you output i.e. C/C++ file

Guru
sorry, I don't really understand your suggestion :(I'm talking about real C++ file; I can't define a "custom build" for it - I don't want to change how my project builds, I'm just looking for a way to (more easily) inspect the output of the preprocessor (in some cases, due to macros, compiler errors may not be very trivial to figure out, actually looking at the preprocessor output helps a lot). And just preemptively: I'd agree with the "overcomplicated macros" argument, but this is not the point... that's not what I want to discuss :)
Virgil
+1  A: 

There's no really elegant way of doing this using the External Tools menu, but here's a solution that will work:

  1. Create a new configuration for your project. Call it something like "Debug-Preproc". In this configuration, set the /P switch for the compiler. (Preprocess, no compilation.)

  2. Go to the External Tools setup menu. Create a new item called "Preprocess Project". Set the options to:

    • Command: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe
    • Arguments: $(ProjectDir)$(ProjectFileName) /Build "Debug-Preproc|Win32"

You can now use the "Preprocess Project" option on your menu to run the preprocessor against all source files in the currently selected project. It will generate [filename].i for each one, which you can open in a text editor.

If you want, you can create an additional step to open the file in a text editor by adding a new external tool to your editor to open $(ItemFileName).i.

It's not nearly as clean or convenient as being able to right-click a file and pick "preprocess", but I think it's the best you'll get short of writing an extension.

Dan Story
Not exactly the solution I've been hoping for, but I guess it's as close as it gets, rather than letting the bounty waste I might as well assign it to you. Thanks :)
Virgil
You know, it just occurred to me -- all the compiler options are actually meaningless when it comes to the preproccessor. The only things that will matter in the generated output are the options on the preprocessor page itself, most of which you probably aren't changing. So if you just set the external tool to CL /P the file you should get the same output as if you build the project using the method I suggested.
Dan Story
Not true, I have plenty of defines in the command line, also paths for include directories... and this is pretty common, I think.
Virgil