Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.