How to debug visual studio pre / post build events

Sometime you add pre/post build event to your project and the build event fails.

How can you spot what exactly caused the fail?

There are several way to spot the error :

1. Use 'rem' to mark a line as remark like you used to do in dos batch files and spot the line with the error

2. Use redirection to a file meaning add '> mydebuginfo.txt' and search for that file in the bin\debug directory.
    inside this fill you will find the error which caused the build to fail.

A much nicer and easier way would be to get the error in a message box, don't you think ?

1. Download Frank Westlake Popup utility (Batch file message box which can take pipe input)

2. Put popup.exe somewhere in your path (ie. c:\windows )

2. Add pipe redirection at the end of the line the suspicious line ' | popup'
    and you'll get a message box describing the error.

Another way is to check the bin\debug dir for 'PreBuildEvent.bat' or 'PostBuildEvent.bat' which are the file that Visual Studio creates and run during the build events, if there is an error the files remain in the output dir and you can run them manually and spot the error.

2 Comments

  • Hello Ohad,
    I am using Visual Studio .NET 2003 and writing a C++ application. Whether there are errors or not, the post-build .bat file is deleted. The output from the .exe file (which is a unit test executable) does not print to the output window even though it does show up when run in a cmd file. If you have any ideas why these things are happening, I would welcome your help.

  • Hi,

    This is Ravinder, I have two solutions. second solution is using the first solution(console application) in Build Events. Means when i will build the second solution first solution exe is get excuted.
    my question is here out to debug the first solution(i.e exe) when i build the second solution.

    Regards,
    Ravinder

Comments have been disabled for this content.