我正在使用以下代码使用PowerShell构建一些项目,但这需要将近30分钟的时间,而且有时也需要更多的时间,这是我在本地执行它时获得的PowerShell脚本建立在
$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;
}
}
}
所以我可以告诉我为什么这需要花费很多时间
答案 0 :(得分:0)
对代码进行小的更改将影响整体性能。除了使用Start-Process,您还可以使用以下代码:
$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()