Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Be Careful in Printing 'Error:' in Custom Build Events of Visual Studio

0.00/5 (No votes)
20 Apr 2014 1  
Your build will fail if you print 'Error:' in your custom Build Events of Visual Studio.

Introduction

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 phenomenon.

Examples

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 ...'.

Solution

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here