Click here to Skip to main content
12,748,873 members (38,893 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 20 Apr 2014

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

, 20 Apr 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Your build will fail if you print 'Error:' in your custom Build Events of Visual Studio.


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.


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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Zhuyun Dai
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.

You may also be interested in...


Comments and Discussions

Suggestionsome background information on error and warning messages Pin
Vincent02616-Oct-15 3:23
memberVincent02616-Oct-15 3:23 
SuggestionConnect Pin
DaveAuld20-Apr-14 23:44
protectorDaveAuld20-Apr-14 23: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 21 Apr 2014
Article Copyright 2014 by Zhuyun Dai
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid