Skip to content

Instantly share code, notes, and snippets.

@csMACnz
Created May 6, 2016 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csMACnz/6b736c9109023af4c09f6f0b9405081b to your computer and use it in GitHub Desktop.
Save csMACnz/6b736c9109023af4c09f6f0b9405081b to your computer and use it in GitHub Desktop.
Treat Warnings As Errors for a folder of csprojs
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