MSB3073: Easy mistake which can break the Post-Build Event

c0d35a107 41 Reputation points
2021-02-26T15:59:35.993+00:00

Create an empty project with this in main.cpp

c++
    #include <iostream>
    int main(int argc, char** argv) {
        std::cout << "    error   exception :      " << std::endl;
        exit(0);
    }

Call this: RetVal.exe

Create a new project and add a Post-Build event where you run this executable
Now visual studio will ALWAYS tell this:
output:
EXEC : error exception:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073:
The command "C:\Perforce\Projects\Retval2\x64\Debug\RetVal.exe
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073:
:VCEnd" exited with code -1.

This works with any both Visual Studio 2015 and 2019.
EDIT: The reason for this is that VisualStudio IDE will interpret lines in the output as Viorel describes below.

Note that if you run this in a bat file "echo %errorlevel%" will of course give 0 as output.

The reason we found this was that we wanted to run gtest as a post-build event and one of the test cases outputs "error exception : " (as expected).

We interpreted it as: gtest returned -1 while it actually returns 0.
All it actually said was that ":VCEnd" exited with code -1".

A bit confusing perhaps but still working as intended I guess.

Developer technologies | Visual Studio | Debugging
Developer technologies | C++
Developer technologies | Visual Studio | Other
Community Center | Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.9K Reputation points
    2021-02-26T16:13:48.253+00:00

    If the RetVal.exe tool returns 0, but also outputs some lines that are interpreted by Visual Studio as error or warning messages (see https://learn.microsoft.com/en-us/cpp/build/formatting-the-output-of-a-custom-build-step-or-build-event), then try this Post-Build command:

    RetVal > nul

    If you want to keep and investigate the output of the tool, you can write it to a file, for example:

    RetVal > results.txt

    If in fact you want to see the results in Output window, then avoid writing interpretable lines.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.