Welcome to MSDN Blogs Sign in | Join | Help

MSBuild / Visual Studio aware error messages and message formats

MSBuild recognizes error messages and warnings that have been specially formatted by many command line tools that typically write to the console. For instance, take a look at the following error messages - they are all properly formatted to be MSBuild and Visual Studio friendly.

    Main.cs(17,20): warning CS0168: The variable 'foo' is declared but never used

   

    C:\dir1\foo.resx(2) : error BC30188: Declaration expected.

   

    cl : Command line warning D4024 : unrecognized source file type 'foo.cs', object file assumed

   

    error CS0006: Metadata file 'System.dll' could not be found.

 

These messages confirm to special format that is shown below, and comprise 5 parts - the order of these parts are important and should not change: 

Origin (Required)

Origin can be blank. If present, the origin is usually a tool name, like 'cl' in one of the examples. But it could also be a filename, like 'Main.cs' shown in another example. If it is a filename, then it must be an absolute or a relative filename, followed by an optional paranthesized line/column information in one of the following forms:

 

        (line) or (line-line) or (line-col) or (line,col-col) or (line,col,line,col)

 

Lines and columns start at 1 in a file - i.e. the beginning of a file is 1, and the leftmost column is 1. If the Origin is a tool name, then it must not change based on local - i.e. it needs to be locale neutral.

 

Subcategory (Optional)

Subcategory is used to classify the category itself further, and should not be localized.

 

Category (Required)

Category must be either 'error' or 'warning'. Case does not matter. Like origin, category must not be localized.

 

Code (Required)

Code identifies an application specific error code / warning code. Code must not be localized and it must not contain spaces.

 

Text (Optional)

User friendly text that explains the error, and *must* be localized if you cater to multiple locales.

 

So, how does MSBuild use Errors and Warnings emitted by external tools?

When MSBuild calls command line tools (for instance, csc.exe or vbc.exe), it looks at the output emitted by the tool to standard out / standard error streams. Any lines that match the error format that I just described will be treated specially - i.e. lines that are recognized as errors or warnings will be turned into build errors and warnings respectively.

 

So, what's the big deal about this anyway? (Here comes the really cool part) :)

To see the real benefit of this, you have to be building from within Visual Studio. Because MSBuild treats these messages specially, they get logged as first class warnings and errors in the Visual Studio task list. If the Origin specifies line/column information, then double clicking on the message will take you to the source of the error in the offending file.

 

[ Author : Faisal Mohamood ]

Published Friday, November 03, 2006 1:17 AM by msbuild

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Tuesday, November 07, 2006 12:39 PM by Keith Hill

# re: MSBuild / Visual Studio aware error messages and message formats

This is really cool.  One minor problem is that I get two errors in the VS task list.  One for the error picked up by parsing the output (awesome - thanks) and the other because the tool returned an error code.  I'm invoking the tool using the error task.  If I set IgnoreExitCode to false, the second error caused the by exit code doesn't show up but then again MSBUILD thinks the target succeeded when it really failed.  Is there a way that I can have my cake and eat it too?

Tuesday, November 07, 2006 12:41 PM by Keith Hill

# re: MSBuild / Visual Studio aware error messages and message formats

Doh that should read that I'm invoking the command line exe using the "Exec" task.

Thursday, January 04, 2007 4:24 AM by Britney

# re: MSBuild / Visual Studio aware error messages and message formats

Hello, nice site look this:

<a href="http://urlzip.de/5m9">chanel handbags</a>

End ^) See you

Monday, March 12, 2007 6:32 AM by ...

# re: MSBuild / Visual Studio aware error messages and message formats

mmm.. nice design, I must say..

Wednesday, March 14, 2007 9:36 PM by ...

# re: MSBuild / Visual Studio aware error messages and message formats

Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast!

Sunday, March 18, 2007 11:10 AM by ...

# re: MSBuild / Visual Studio aware error messages and message formats

luogo grande:) nessun osservazioni!

Tuesday, March 20, 2007 2:06 AM by ...

# re: MSBuild / Visual Studio aware error messages and message formats

Chi ha fatto questo? E un buon posto per trovare le informazioni importanti!:)

Wednesday, May 23, 2007 4:30 AM by hdhucs

# re: MSBuild / Visual Studio aware error messages and message formats

Hi. Cool design. Keep up the good.

Good luck.

Wednesday, May 23, 2007 4:30 AM by hdhucs

# re: MSBuild / Visual Studio aware error messages and message formats

Hi. Cool design. Keep up the good.

Good luck.

Tuesday, June 12, 2007 1:23 PM by Bill

# re: MSBuild / Visual Studio aware error messages and message formats

MSN I NIIPET

<a href="http://msn.com">MSN</a>

Monday, July 02, 2007 8:45 AM by Matt

# re: MSBuild / Visual Studio aware error messages and message formats

Is-it possible to change to language of the errors messages text ?

Thanks

Friday, August 24, 2007 11:34 AM by turha

# re: MSBuild / Visual Studio aware error messages and message formats

Here is the GNU specification for formatting error messages so that line and column numbers can be automatically recognized:

http://www.gnu.org/prep/standards/standards.html#Errors

It says tab stops should be assumed every 8 columns.  Your blog post did not go into such detail.  How should column numbers logged via MSBuild count tabs and CJK fullwidth characters?

Wednesday, September 19, 2007 10:45 AM by Mike

# re: MSBuild / Visual Studio aware error messages and message formats

This is really nice for Errors and Warnings, but how do you get VS to log a simple informational message.  Category only contains error and warning and by experimentation I see that VS ignores attempts at "message", "informational", etc...  Is there a magic incantation?

Wednesday, January 02, 2008 4:16 PM by Chris Kline

# re: MSBuild / Visual Studio aware error messages and message formats

It's worth noting that "warning" and "error" MUST be lower case in order to be recognized. I.e., "Warning" will not be recognized.

Friday, January 11, 2008 7:13 AM by fabiola-wy

# Good site

<a href= http://puhlov.com >mixolgy measurments</a>

Saturday, February 02, 2008 1:09 PM by Greg Popovitch

# re: MSBuild / Visual Studio aware error messages and message formats

I have a problem. When compiling c++ with cl the file names in error messages are lowercased. This is not the case when building from inside Visual Studio 2005. How can I prevent this case change when using cl?

Thanks,

greg

Monday, December 29, 2008 5:56 PM by baztheman

# re: MSBuild / Visual Studio aware error messages and message formats

Hi,

I posted in msdn with a msbuild error code return question but have not been answered hence I am giving this another try...

I am using msbuild from framework version 2.0.50727.1433. I need to be able to capture msbuild error correctly on command line or via batch files. When I type "msbuild sdsd", it does not return non zero. Why?

Here is my msdn forum post if you want more details: http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/82615310-3ac2-4265-87fb-c3d7a4e652fe/

Thank you.

B.

Monday, February 16, 2009 4:48 PM by Hoop Somuah

# re: MSBuild / Visual Studio aware error messages and message formats

" (line) or (line-line) or (line-col) or (line,col-col) or (line,col,line,col)"

(line-col) should read (line,col)

Monday, February 16, 2009 4:52 PM by Hoop Somuah

# re: MSBuild / Visual Studio aware error messages and message formats

also, shouldn't "(line,col,line,col)" be "(line,col-line,col)" for consistency?

where comma separated values in a cordinate (point) and hyphen separates the values in a span

Friday, March 27, 2009 2:37 PM by Joe Chavez

# re: MSBuild / Visual Studio aware error messages and message formats

With regard to:

Messages

Indicates the number of Messages in the list. Click to toggle whether Messages are displayed.

What is the syntax to add "message" to the "Messages" list in the build output.

So far I have:

printf("UnitTest++: info UT100: %d tests passed.\n", totalTestCount);

printf("UnitTest++: message UT100: %d tests passed.\n", totalTestCount);

printf("UnitTest++: warning UT100: %d tests passed.\n", totalTestCount);

printf("UnitTest++: error UT100: %d tests passed.\n", totalTestCount);

The first 2 "info" and "message" do not show up in the "Messages" list. The "warning" and "error" work as expected.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker