# Examine an MSBuild log and issue an error if any MSBulid warnings are discovered.

param ([string]$logFile = $(throw "Need a build log file"))
$ErrorActionPreference="Stop"

try
{
    $exitCode = 0
    $pattern = "\bwarning\b\s+\bMSB(\d+):(.*)"
    foreach ($line in gc $logFile) {
        $m = [regex]::match($line, $pattern, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
        if ($m.Success) {
            $num = $m.Groups[1].Value
            $text = $m.Groups[2].Value
            $location = $line.Substring(0, $m.Index)
            write-host ("error MSB{0}: {1} -> {2}" -f $num, $text, $location)
            write-host "Original MSB warning line below"
            write-host $line
            $exitCode = 1
        }
    }

    exit $exitCode
}
catch
{
    write-host "Error: $($_.Exception.Message)"
    exit 1
}


# Examine an MSBuild log and issue an error if any MSBulid warnings are discovered.

param ([string]$logFile = $(throw "Need a build log file"))
set-strictmode -version 2.0
$ErrorActionPreference="Stop"

try
{
    $exitCode = 0
    $pattern = "\bwarning\b\s+\bMSB(\d+):(.*)"
    $ignoreCase = [System.Text.RegularExpressions.RegexOptions]::IgnoreCase
    foreach ($line in gc $logFile) {
        $m = [regex]::Match($line, $pattern, $ignoreCase)
        if ($m.Success) {
            $num = $m.Groups[1].Value
            $text = $m.Groups[2].Value
            $location = $line.Substring(0, $m.Index)

            # MSBuild race condition.  Doesn't break build so don't promote to error for now
            #
            # https://github.com/dotnet/roslyn/issues/10116
            if ($num -eq 3491 -and [regex]::Match($text, "Could not write lines to file.*Portable", $ignoreCase)) {
                continue
            }

            write-host ("error MSB{0}: {1} -> {2}" -f $num, $text, $location)
            write-host "Original MSB warning line below"
            write-host $line
            $exitCode = 1
        }
    }

    exit $exitCode
}
catch
{
    write-host "Error: $($_.Exception.Message)"
    exit 1
}


Work around MSBuild race condition
Work around MSBuild race condition
