Search code examples
visual-studiomsbuildpost-build-eventtargets

Why outputting 'error: ' in Post-Build Event breaks my build in VS2012?


Adding

cmd.exe /c "ECHO error : unexplainable"

causes this:

1>------ Build started: Project: xxx, Configuration: Debug Win32 ------
1>EXEC : error : unexplainable
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(134,5): error MSB3073: The command "cmd.exe /c "ECHO error : unexplainable"
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(134,5): error MSB3073: :VCEnd" exited with code -1.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

It happens only when 'error' string is followed by a ':' character.


Solution

  • It is a bug in MSBuild: https://github.com/Microsoft/msbuild/issues/766

    The 'Exec' task used by the 'PostBuildEvent' target should have the 'IgnoreStandardErrorWarningFormat' set to true by default but it doesn't, so it fails when finding 'error:' in the output.

    An unreliable way to fix this is to modify the 'PostBuildEvent' target in C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets (at line 134) by adding IgnoreStandardErrorWarningFormat="true" to the 'Exec' task

    Override predefined 'PostBuildEvent' in your project like here: Can I include a .targets file in a .props property sheet?