Created
May 6, 2016 15:55
-
-
Save csMACnz/6b736c9109023af4c09f6f0b9405081b to your computer and use it in GitHub Desktop.
Treat Warnings As Errors for a folder of csprojs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get-childitem . -include *.csproj -recurse -ErrorAction SilentlyContinue | %{ | |
$_.FullName | |
[xml]$proj = get-content $_.FullName | |
$modified = 0 | |
$proj.Project.PropertyGroup | | |
where-object { $_.Condition -match 'Configuration.*Platform.*(Debug|Release)' } | %{ | |
if (-not $_.TreatWarningsAsErrors) { | |
$node = $proj.CreateElement('TreatWarningsAsErrors', $proj.Project.NamespaceURI) | |
$node.InnerText = 'true' | |
$node = $_.AppendChild($node) | |
$modified = 1 | |
} | |
if ($_.TreatWarningsAsErrors -ne 'true') { | |
$_.TreatWarningsAsErrors = 'true' | |
$modified = 1 | |
} | |
if (-not $_.WarningLevel) { | |
$node = $proj.CreateElement('WarningLevel', $proj.Project.NamespaceURI) | |
$node.InnerText = "4" | |
$node = $_.AppendChild($node) | |
$modified = 1 | |
} | |
if ($_.WarningLevel -ne "4") { | |
$_.WarningLevel.InnerText = "4" | |
$modified = 1 | |
} | |
} | |
if ($modified -eq 1) { | |
$proj.Save($_.FullName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment