How to graph number of warnings from MSBuild?

I want to add a graph for the number of warnings in my build.  I am currently running a MsBuild task that builds a Visual Studio Solution.

I started with (in the main-config.xml)

  <graph title="Number of Warnings">
    <valueType key="InspectionStatsW" title="Warnings" />

But it doesn't show up (except occasionally when it shows no data).  So I am guessing that the variable InspectionStatsW doesn't apply to msbuild.

So after some research I started to try and use a custom msbuild logger that would fire a team city Service Message.

My logger looks like this:

    public class WarningLogger : Logger
        private int _warningCount;

        public override void Initialize(IEventSource eventSource)
            eventSource.WarningRaised += EventSourceWarningRaised;

        void EventSourceWarningRaised(object sender, BuildWarningEventArgs e)

        public override void Shutdown()
            Console.WriteLine("##teamcity[buildStatisticValue key='warnings' value='{0}']",_warningCount);

When I run msbuild command line it works great and dumps  "##teamcity[buildStatisticValue key='warnings' value='0']" to the console window.

But when I call it from Team City (by adding a command line argument to my msbuild step configuration) it runs fine, but the message doesn't show in the build log.  

Is there a better way I can fire the message to get it to show up as part of the build log so that I can use it in my graph?


PS. Awesome product by the way.
Comment actions Permalink

TeamCity msbuild runner provides own msbuild logger to capture msbuild events.
Probably, this solution should provide delegation for another logger (fell free to create an issue in the issue tracker)

Please see discussion for a workaround.

Comment actions Permalink

Thanks for the reply,

So as a work around, you are suggesting I write my own build runner?


Comment actions Permalink

Not necessary to write a custom logger.

What you need are
- create you logger that delegated to TeamCity build logger
- in your msbuild script start MSBuild.exe with your logger (that will delegate to TeamCity logger too)

Comment actions Permalink

Thanks for your help.

In the end I went with the slightly simpler (but not as pretty) solution of writing my results out to a text file and then getting a seperate msbuild task to redisplay them.

<Target Name="OutputWarningCount">

      <Message Text="Warnings file does not exist!!!" Condition="!Exists('c:\WarningCountFile.txt')"/>
         File="c:\WarningCountFile.txt" >

      <Message Text="##teamcity[buildStatisticValue key='warnings' value='@(WarningCount)']"/>

Then I just call the 'OutputWarningCount' build target from my msbuild runner.  

Hopefully in future TeamCity will have a warning count variable available for MSBuild runners and I can just delete this.
Comment actions Permalink

Feel free to post an issue in the issue tracker at for supporting of warnings count statistics in TeamCity.


Please sign in to leave a comment.