Developer
Developer

Reputation: 8636

Powershell build solution using devenv.exe taking much time

I am using the following code to build some projects using PowerShell but this is taking nearly 30 minutes of time and some times it is taking more than that too, here is the PowerShell script I had when I execute it locally it is getting build in

$sourceDirectory = "D:\Service"
$SolutionToBuild = @("Solution1.sln","Solution2.sln","Solution3.sln","Solution4.sln")

$projectFiles = Get-ChildItem -Path "$sourceDirectory" -Filter *.sln -Recurse


foreach($solution in $SolutionToBuild)
{
     foreach($projectFile in $projectFiles)
    {
           if($projectFile.Name -eq $solution)
           {
                 write-host $projectFile.Name;
                 $SlnFilePath = $projectFile.FullName
                 $BuildParameters = """$SlnFilePath"" /Build Release|x86"
                 $CleanParameters = """$SlnFilePath"" /Clean Release|x86"
                 Start-Process -FilePath $vsPath -ArgumentList $CleanParameters -Wait
                 Start-Process -FilePath $vsPath -ArgumentList $BuildParameters -Wait
                 break;
           }
     }
}

So can one let me know why this taking much time

Upvotes: 0

Views: 857

Answers (1)

tgpdyk
tgpdyk

Reputation: 1233

A minor change to the code will affect the total performance. Instead of using Start-Process, you may use the following code:

 $buildProcInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -ArgumentList "devenv.exe", $buildArgs
 try { $buildProcess = [System.Diagnostics.Process]::Start($buildProcInfo) }
 catch {
          Write-Host "Error"
          # exit?
        }
 $buildProcess.WaitForExit()

Upvotes: 1

Related Questions