I’ve been working with Powershell on and off for a while now and wanted a tool to do a search through a directory (a single pull of a VCS repository) find all .sln files and build them all with MSBuild and report the results:
param([string]$rootPath)
$sln_files = Get-ChildItem -Filter *.sln -Recurse -Path $rootPath
$fails = @{}
$passes = @{}
foreach($sln in $sln_files)
{
try
{
$sln.FullName
$clean = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe """ + $sln.FullName + """ /t:Clean /m"
Write-Host $clean
Invoke-Expression $clean
$build = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe """ + $sln.FullName + """ /t:Build /m"
Write-Host $build
Invoke-Expression $build
if($LastExitCode -ne 0)
{
Write-Host "########## FAIL ########"
$fails.Add($sln.Fullname,$sln)
}else
{
Write-Host "########## PASS ########"
$passes.Add($sln.FullName,$sln)
}
}
catch
{
$fails.Add($sln.FullName,$sln)
}
}
Write-Host $fails.Count Failed
Write-Host $passes.Count Passed
Write-Host "FAILS"
$fails
Write-Host "PASSES"
$passes
I just set it off against a big pile o’ code (some gnarly, some clean) and the results are pretty much as I expected.
