A few years back, I posted “Displaying .Net Build Warnings in TeamCity”. Many folks found it useful (and it served as a good reference the last time I needed to re-setup warnings). Recently, Mitch Terlisner reached out to me with a much improved version to share with folks that includes better build status output, an interactive warnings tab, statistics chart, and a custom metric to enable custom failure rules:

Better Warning Output in build status!

Improved output in your build status

Improved build status

Way better (interactive) Warning Output tab!

Interactive Build Warning tab with the assembly hierarchy

Interactive Build Warning tab

Build Warnings Statistics Chart!

A chart in the Statistics tab of the project

Statistics Chart

Custom Failures on Build Warning Count!

Custom failure when warning count exceeds a given number

Custom failures

This version was shared by Mitch T, on behalf of (and with permission of) Markit.

A few highlights:

  • Supports multiple solutions, and displays warnings in a hierarchy, by solution/project.

  • Shows counts of warnings by solution/project/warning code, and shows which warnings are most numerous.

  • Interactive – allows expanding/collapsing at the solution/project, and filtering to new warnings or by warning code(s).

Mitch Terlisner

www.improving.com

Setup

Here are the setup steps in TeamCity:

Build Changes

Mitch added these parameters and steps to his build template to apply to multiple builds, another option would be to edit an existing build directly.

Download the powershell script here: BuildWarningReportGenerator.ps1 Gist

  1. Select the “Parameters” menu.

  2. Add a a parameter for the Build Log name that we’ll generate from MSBuild:

Name: BuildLogFile
   Value: BuildLog.Log
  1. Add command line argument we need to pass to MSBuild to do so:
Name: MSBuildLogClause
   Value: /l:FileLogger,Microsoft.Build.Engine;logfile=%BuildLogFile%;Append

Add Parameters

Next we’ll want to add build steps to purge any prior versions of the file, run the log during MS Build calls, and then evaluate the log file for warnings at the end of the run.

Build Steps

1. Purge Build Log

Type: Command Line
Name: Purge BuildLogFile
Run:  Custom Script
Script: if exist %BuildLogFile% del %BuildLogFile%

2. Existing MSBuild Task

Append to the CommandLine Input: %MSBuildLogClause%

3. Evaluate Build Warnings

Type: Powershell
Name: Generate Build Warnings Report
Working Dir: 
Script: Source code
Source:
 if(test-path .\BuildWarningReportGenerator.ps1){ .\BuildWarningReportGenerator.ps1 -BuildLogPath "\%BuildLogFile%" -BuildCheckoutDirectoryPath "\" -BuildArtifactRepositoryUrl "%teamcity.serverUrl%/repository/download/%system.teamcity.buildType.id%/" } # ** Requires two trailing lines to work correctly 
Mode: Put Script into PowerShell stdin with "-Command =" argument
Advanced Settings:  Add -NoProfile argument

Report Tab

To add a report tab with the warning information in TeamCity:

Add Report Tab

  1. Open the Project and click “Edit Project Settings” and select the Report Tab

  2. Click the “Create new build report tab” button

  3. Enter settings and press Save

Tab title: Build Warnings
Start page: .teamcity/BuildWarningReport.zip!BuildWarningReport.html

Chart

You can add a chart to an individual build configuration via the UI, but you have to edit a TeamCity configuration if you want to add it to a Build Template or a Project. Mitch included the instructions for the config so we can do an edit once, apply many approach:

Edit config/projects/[your project folder]/pluginData/plugin-settings.xml, and merge in these settings:

<settings>
	<buildtype-graphs>
		<graph title="Build Warnings" defaultFilters="" hideFilters="" id="customGraph1" seriesTitle="Serie">
			<valueType key="buildWarnings" title="buildWarnings" color="#ffcc00" />
		</graph>
	</buildtype-graphs>
</settings>

Custom Metric

Recording the warning count in a custom metric will enable you to create a custom build failure based on the warning count:

Edit config/main-config.xml, and merge in these settings

<server>
	<build-metrics>
		<statisticValue key="buildWarnings" description="number of build warnings"/>
	</build-metrics>
</server>

Closing

I wanted to thank Mitch again for sending back the improvements he made on the original. This is a level or two above my original post and I’m already applying some of the changes to my own builds.