有时我在 Unity Editor 中构建我的项目,花费的时间不到一分钟。
但我也喜欢进行命令行构建,我注意到这需要十分钟。有什么办法可以解决这个问题,让它构建得更快吗?这是我的命令行的样子——我使用 powershell,以便在构建实际完成之前批处理文件不会继续。也许它与“-Wait”有关,但如果我不将其放在命令行中,则会在构建完成之前继续。
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
最佳答案
我在构建时通过仔细观察流程终于弄明白了这一点。事实证明,如果您有脚本,构建过程也会导致 VBCSCompiler.exe 运行。如果它是由 Unity 启动的,那么它将成为启动的进程树的一部分。它会保持打开十分钟,以防有更多工作要做。参见 here for more info .
因此,为了解决这个问题,我更改了我的代码:
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"
https://stackoverflow.com/questions/65225251/