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" />
  </graph>



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)
        {
            _warningCount++;
        }

        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?

Thanks,
rk

PS. Awesome product by the way.
7 comments

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 http://devnet.jetbrains.net/message/5277698#5277698 discussion for a workaround.

0

Thanks for the reply,

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

rk

0

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)

0

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')"/>
        <ReadLinesFromFile
         File="c:\WarningCountFile.txt" >
          <Output
              TaskParameter="Lines"
              ItemName="WarningCount"/>
        </ReadLinesFromFile>

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



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.
0

Feel free to post an issue in the issue tracker at http://youtrack.jetbrains.net for supporting of warnings count statistics in TeamCity.

0

Please sign in to leave a comment.