I found a weird behavior of Visual Studio 2012
recently. If you have a custom pre-build or post-build event which prints
both ‘error’ and ‘:’ in a single line (‘error’ should be before
‘:’, case insensitive), VS will treat your build as failure. Therefore, if
you don’t want VS to fail your build, do not print ‘error’ and ‘:’ in this way.
I think this is MSBUILD’s behavior because our TFS build also has this
Here is an example, I wrote a PowerShell script as the custom build event for a test project as below:
write-host No error anything: my god
Then I built the project and got it failed. The Output panel showed:
And the error list showed:
You can see the message pattern - 'error ... :' causes Visual Studio to treat the build failed with some error and Visual Studio picked 'my god' as the error message! That's very weird because my actual message is 'No error ...'.
We have to avoid printing 'Error' and ':' in one line in order since Microsoft is so tricky in error handling and we have to adapt it.