Click here to Skip to main content
Click here to Skip to main content
Go to top

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

, 20 Apr 2014
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.

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

Share

About the Author

Zhuyun Dai
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.
Follow on   LinkedIn

Comments and Discussions

 
SuggestionConnect PinprotectorDaveAuld20-Apr-14 22:44 

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

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

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