Click here to Skip to main content
15,881,803 members
Articles / DevOps / TFS
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
20 Apr 2014CPOL 12.6K   4   2
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:

Image 1

And the error list showed:

Image 2

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
China China
Over 10-years experience in using Microsoft technologies.
At present, working as the architect of a clustered real-time data delivery and visualization system, responsible for the design of component architecture, product packaging and deployment, also targeting private cloud solutions for future.

Comments and Discussions

 
Suggestionsome background information on error and warning messages Pin
Vincent02616-Oct-15 2:23
Vincent02616-Oct-15 2:23 
SuggestionConnect Pin
DaveAuld20-Apr-14 22:44
professionalDaveAuld20-Apr-14 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.