首页 > 解决方案 > Unity.exe 命令行构建需要 10 分钟,但编辑器需要不到一分钟

问题描述

有时我在 Unity 编辑器中构建我的项目,只需要不到一分钟的时间。

但我也喜欢做一个命令行构建,我注意到这需要十分钟。有什么办法可以解决这个问题,让它构建得更快吗?这是我的命令行的样子——我使用 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

标签: powershellunity3d

解决方案


我最终通过在构建时密切观察过程来弄清楚这一点。事实证明,如果您有脚本,构建过程也会导致 VBCSCompiler.exe 运行。如果这是由 Unity 启动的,那么它将是启动的进程树的一部分。它会保持开放十分钟,以防有更多工作要做。请参阅此处了解更多信息

所以为了解决这个问题,我改变了我的代码:

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"

推荐阅读