Skip to content

AppVeyor will treat warnings as errors and fail the build with the help of this PowerShell script.

Notifications You must be signed in to change notification settings

JoeRall/TreatWarningsAsErrors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Treat Warnings As Errors

Build status

The build is failed because this project currently has warnings 😄

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.

References

About

AppVeyor will treat warnings as errors and fail the build with the help of this PowerShell script.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published