.Net Compilation Using Powershell

#this will compile solutions list provided to it.
#script to restore the pacakge
//[cmdletBinding()]
param
(
[parameter(Mandatory = $true)]
$Solutions, #relative to bamboo working directory
//[parameter(Mandatory = $true)]
$BuildWorkingDirectory,
[parameter(Mandatory = $true)]
$MSBuildExe,
[parameter(Mandatory = $true)]
$outdir,
[parameter(Mandatory = $true)]
$configuration,
[parameter(Mandatory = $false)]
$platform
)
$SlnList = $Solutions -split “;”
foreach($Sln in $SlnList)
{
$sln = Join-Path $BuildWorkingDirectory $sln
Write-Host “$sln”

if(Test-Path $Sln)
{
try
{
Write-Host ‘Executing’ “””$MSBuildExe””” “””$sln””” /p:SkipInvalidConfigurations=true /p:VisualStudioVersion=12.0 /p:GenerateProjectSpecificOutputFolder=true /p:AllowedReferenceRelatedFileExtensions=none /m /p:OutDir=”””$outdir””” /p:Configuration=”””$configuration””” /p:Platform=”””$platform”””
#$erroOut = & $MSBuildExe “””$sln””” /p:SkipInvalidConfigurations=true /p:VisualStudioVersion=12.0 /p:GenerateProjectSpecificOutputFolder=true /p:AllowedReferenceRelatedFileExtensions=none /m /p:OutDir=”””$outdir””” /p:Configuration=”””$configuration”””
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.CreateNoWindow = $true
$pinfo.UseShellExecute = $false
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardError = $true
$pinfo.FileName = “””$MSBuildExe”””
if($platform)
{
Write-Host “Hello” $platform
$pinfo.Arguments = “””$sln”” /p:SkipInvalidConfigurations=true /p:VisualStudioVersion=12.0 /p:GenerateProjectSpecificOutputFolder=true /p:AllowedReferenceRelatedFileExtensions=none /m /p:OutDir=””$outdir”” /p:Configuration=””$configuration”” /p:Platform=””$platform”””
}
else #if no platform is provided.(like in SVE)
{
$pinfo.Arguments = “””$sln”” /p:SkipInvalidConfigurations=true /p:VisualStudioVersion=12.0 /p:GenerateProjectSpecificOutputFolder=true /p:AllowedReferenceRelatedFileExtensions=none /m /p:OutDir=””$outdir”” /p:Configuration=””$configuration”””
}
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $pinfo
[void]$process.Start()
$output = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
Write-Host $output
if($output.Contains(“Build FAILED.”))
{
$pos = $output.IndexOf(“Build FAILED.”)
$errorLog = $output.Substring($pos)
Write-Error “Build failed for $Sln…Here are the details…. $errorLog”
throw “Build failed for $Sln…Here are the details…. $errorLog”
exit 500
}
}
catch [Exception]
{
$_.Exception.GetType().FullName, $_.Exception.Message
Write-Error “error compiling $sln”
}
}
else
{

Write-Error ‘Solution File Doesnot exist’
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *