AppVeyor will treat warnings as errors and fail the build with the help of this PowerShell script:
Get-ChildItem -Recurse -Filter "*.*csproj" | % {
$filename = $_.Fullname
$proj = [xml]( Get-Content $_.Fullname )
$xmlNameSpace = new-object System.Xml.XmlNamespaceManager($proj.NameTable)
$xmlNameSpace.AddNamespace("p", "http://schemas.microsoft.com/developer/msbuild/2003")
$nodes = $proj.SelectNodes("/p:Project/p:PropertyGroup[@Condition and not (p:TreatWarningsAsErrors)]", $xmlNameSpace)
$touched = $false
$nodes | ForEach-Object -Process {
$e = $proj.CreateElement("TreatWarningsAsErrors", "http://schemas.microsoft.com/developer/msbuild/2003")
$e.set_InnerText("true")
$_.AppendChild($e) | Out-Null
$touched = $true
}
if ($touched) {
$proj.Save("$($filename)") | Out-Null
Write-Host $_.Name " - Warnings are now Errors"
}
}
You can wire the script up inside the install build step like so:
install:
- ps: .\BuildScripts\TreatWarningsAsErrors.ps1
Special thanks to David and Josh for the code and inspiration.