Build Visual Studio project by Powershell
#Build Visual Studio Project
function Build($ProjectPath, $rebuildParam)
{
$buildOutput = & $MSBuildPath $ProjectPath $rebuildParam
#find 'Error(s)/Warning(s)' text in buildOutput, take first part(number as string) and convert it to number
$output = @([int](($buildOutput | where {$_.Contains("Error(s)")}).Trim().Split(" ")[0]), [int](($buildOutput | where {$_.Contains("Warning(s)")}).Trim().Split(" ")[0]))
return $output
}
$MSBuildPath = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
$rebuildParam = "/t:rebuild"
$ProjectPath = "c:\x\MyProject.csproj"
#Output is array, e. g. (0, 1) in case of 0 Errors, 1 Warnings
Build $ProjectPath $rebuildParam