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.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,600 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,526 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
938 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,949 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K 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