Unity.exe takes 10 minutes for command-line build, but less a minute from editor

Viewed 934

Sometimes I build my project in Unity Editor and it takes way less than a minute.

But I also like to do a command line build and I noticed that takes ten minutes. Is there a way I can fix that so it builds faster? Here is what my command line looks like -- I use powershell so that the batch file does not continue before the build actually finishes. Maybe it has to do with the "-Wait" but if I don't put that in the command line continues before the build finishes.

powershell -Command "Start-Process -FilePath C:\Users\me\source\Unity\Editors\2019.3.5f1\Editor\Unity.exe -ArgumentList '-batchmode -projectpath C:\Users\me\source\repos\MyProject -buildWindows64Player C:\mybuild\MyProject.exe -quit' -Wait" time /T
1 Answers

I finally figured this out by closely watching processes when I was building. It turns out that if you have scripts, the build process causes VBCSCompiler.exe to run as well. If this was launched by Unity then it will be part of the process tree that was launched. It stays open for ten minutes in case there is more work for it to do. See here for more info.

So to work around this, I changed my code:

powershell -Command "$unity = Start-Process -FilePath C:\Users\me\source\Unity\Editors\2019.3.5f1\Editor\Unity.exe -ArgumentList '-batchmode -projectpath C:\Users\me\source\repos\MyProject -buildWindows64Player C:\mybuild\MyProject.exe -quit' -PassThru; Start-Sleep -Seconds 3.0; Write-Host -NoNewLine 'Building...'; while ((Get-WmiObject -Class Win32_Process | Where-Object {$_.ParentProcessID -eq $unity.Id -and $_.Name -ne 'VBCSCompiler.exe'}).count -gt 0) { Start-Sleep -Seconds 1.0; Write-Host -NoNewLine '.' }; if (!$unity.HasExited) { Wait-Process -Id $unity.Id }; exit $unity.ExitCode"
Related