Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"preprocess current file" addin for Visual Studio? (C++ )

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?

like image 216
Virgil Avatar asked Mar 22 '10 10:03

Virgil


1 Answers

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.

like image 136
Dan Story Avatar answered Oct 06 '22 04:10

Dan Story