次の方法で共有


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: 

(See image here)

 

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 ]

Comments

  • Anonymous
    November 07, 2006
    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?

  • Anonymous
    November 07, 2006
    The comment has been removed

  • Anonymous
    January 03, 2007
    Hello, nice site look this: <a href="http://urlzip.de/5m9">chanel handbags</a> End ^) See you

  • Anonymous
    March 11, 2007
    mmm.. nice design, I must say..

  • Anonymous
    March 14, 2007
    Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast!

  • Anonymous
    March 18, 2007
    luogo grande:) nessun osservazioni!

  • Anonymous
    March 19, 2007
    Chi ha fatto questo? E un buon posto per trovare le informazioni importanti!:)

  • Anonymous
    May 22, 2007
    Hi. Cool design. Keep up the good. Good luck.

  • Anonymous
    May 22, 2007
    Hi. Cool design. Keep up the good. Good luck.

  • Anonymous
    June 12, 2007
    MSN I NIIPET <a href="http://msn.com">MSN</a>

  • Anonymous
    July 02, 2007
    Is-it possible to change to language of the errors messages text ? Thanks

  • Anonymous
    August 24, 2007
    The comment has been removed

  • Anonymous
    September 19, 2007
    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?

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

  • Anonymous
    January 10, 2008
    <a href= http://puhlov.com >mixolgy measurments</a>

  • Anonymous
    February 02, 2008
    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

  • Anonymous
    December 29, 2008
    The comment has been removed

  • Anonymous
    February 16, 2009
    The comment has been removed

  • Anonymous
    February 16, 2009
    The comment has been removed

  • Anonymous
    March 27, 2009
    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.

  • Anonymous
    April 19, 2012
    Like Joe Chavez, I too really want to know how I can get a message in to the 'Messages' list in the Error List pane of VS2010 via a #pragma message in C++. Please can you help?

  • Anonymous
    May 02, 2014
    This is the appropriate MSDN page which describes the format/syntax quite well. msdn.microsoft.com/.../yxkt8b26.aspx

  • Anonymous
    October 09, 2014
    The comment has been removed