This issue appears to be due to the Library folder being refreshed during a Unity Cloud build. I can reproduce this error by deleting the Library directory and immediately attempting to build. Recompiling gets it back into a good state, but this is not possible during a Unity Cloud build, so I have passed this onto the Dev team to investigate further.
EDIT: As a possible workaround, I have found that forcing a recompile using EditorUserBuildSettings.SwitchActiveBuildTargetAsync
allows it to build succesfully after the Library directory is deleted. Here is an example script:
#if UNITY_EDITOR
using UnityEditor.Build;
using UnityEditor;
public class Build : IActiveBuildTargetChanged
{
private static string destPath = "";
public int callbackOrder { get { return 0; } }
[MenuItem("Tools/Switch and Build")]
public static void SwitchAndBuild()
{
destPath = EditorUtility.OpenFolderPanel("Choose Build Destination", "", "");
if (string.IsNullOrWhiteSpace(destPath))
{
return;
}
/* Switch to a different platfrom to start with, just so we can switch back to Windows
* and leverage the recompile in SwitchActiveBuildTargetAsync
*/
BuildTarget target = BuildTarget.WebGL;
BuildTargetGroup targetGroup = BuildTargetGroup.WebGL;
EditorUserBuildSettings.SwitchActiveBuildTarget(targetGroup, target);
target = BuildTarget.StandaloneWindows64;
targetGroup = BuildTargetGroup.Standalone;
EditorUserBuildSettings.SwitchActiveBuildTargetAsync(targetGroup, target);
}
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget)
{
BuildPlayerOptions options = new BuildPlayerOptions();
options.scenes = new[] { "Assets/Scenes/SampleScene.unity" };
options.locationPathName = destPath + "\\Build.exe";
BuildTarget target = BuildTarget.StandaloneWindows64;
BuildTargetGroup targetGroup = BuildTargetGroup.Standalone;
options.target = target;
options.targetGroup = targetGroup;
BuildPipeline.BuildPlayer(options);
UnityEngine.Debug.Log($"Finished building!");
}
}
#endif