MSB3073 using variables in Post-Build Event

c0d35a107 41 Reputation points


I have a Post-Build Event which looks like follows:

$(BinDir)$(TargetName).$(Extension) --root_dir_abs=$(BinDir)..\cpp\UnitTestRoot

This expands to:

C:\Product\cpp\Solutions\..\..\bin64\Run_Tests.exe --test_dir=C:\Product\cpp\Solutions\..\..\bin64\..\cpp\UnitTestRoot

Including the error message:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: The command "C:\Product\cpp\Solutions\..\..\bin64\Run_Tests.exe --test_dir=C:\Product\cpp\Solutions\..\..\bin64\..\cpp\UnitTestRoot
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :VCEnd" exited with code -1.

This is a perfectly valid line because I can run it by copy-paste to a cmd shell and it runs perfectly well without any errors at all.

I wonder if it is the ".."-notation that is used here a lot causes this error?
EDIT: This is not the problem as I hacked around it and still get the error: Alternatively could it be the option I give to my program "--test_dir=PATH"?
Are there any other possible causes for this error?

By the way I use the Visual Studio 2015 compiler (but within the 2019 IDE).


EDIT: Your formating here shortcuts . . \ and removes the \ -sign at the end... trying to fix it

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,588 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 113.7K Reputation points

    If Run_Tests.exe returns 0, but also outputs some lines that are interpreted by Visual Studio as error or warning messages (see, then try this Post-Build command:

    $(BinDir)$(TargetName).$(Extension) --root_dir_abs=$(BinDir)..\cpp\UnitTestRoot > nul

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

    $(BinDir)$(TargetName).$(Extension) --root_dir_abs=$(BinDir)..\cpp\UnitTestRoot > test_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 comments No comments

2 additional answers

Sort by: Most helpful
  1. Viorel 113.7K Reputation points

    Probably -1 is the exit code of Run_Tests.exe (set by its ‘return -1’ from main function, for example). Non-zero codes usually mean errors.

    Clarify if this is normal for Run_Tests.exe. If it was expected and you want to disregard the errors, then try this command:

    $(BinDir)$(TargetName).$(Extension) --root_dir_abs=$(BinDir)..\cpp\UnitTestRoot & (call )

  2. c0d35a107 41 Reputation points

    Hello I seem to have found a minimal reproducible example that gives this error at all times...
    The compiler is from visual studio 2015.

    int main(int argc, char** argv) {
    std::cout << " error exception : " << std::endl;

    0 comments No comments