Problem: CloudBuild with NuGet and Unity 2020.2 did not work

We have been using NuGetForUnity in UCB without any problems for a long time. It worked like a charm.

Now we have updated to Unity Version 2020.2.X and none of the installed nuget packages is restored during the build. There is also no “Restoring Nuget Packages” Log in the build log file as it was before. It seems like it is just not called. Also no errors concerning nuget package installation.

NuGetForUnity Version is 2.0.1.

I also tried to implement a Pre-Export Method to force the restoring, but this also did not work. Neither any log output could be found from this script.

Switch back to Unity 2020.1.17f1 resolves both of these problems: All Logs are visible and the NuGet packages are included properly.

Is there a known issue or do i have to do something else, since 2020.2?

Thanks a lot.

1 Like

After some additional tests i want to show you my testscript:

using NUnit.Framework;
using NugetForUnity;
using System.IO;
using UnityEditor;
using UnityEngine;

public class CloudPreBuild : MonoBehaviour
{
    public static void NugetRestore()
    {
        Debug.Log("UnityCloudBuild - CloudPreBuild - NugetRestore started");
        NugetHelper.Restore();
    }  
}

[InitializeOnLoad]
public static class NugetCloudHelper
{
    static NugetCloudHelper()
    {
        Debug.Log("UnityCloudBuild - NugetCloudHelper - NugetRestore started");
        NugetHelper.Restore();
    }
}

It can be tested without NuGet: only all lines except the log output have to be commented out. This script can be used to test the malfunction. 2020.1 works fine. 2020.2 unfortunately not.

In UCB Config i added “CloudPreBuild.NugetRestore” as Pre-Export Method. The NugetCloudHelper should be loaded without any additional config because of the [InitializeOnLoad] Attribute.

1 Like

I reported this behavior as a bug and the support team was able to reproduce my request.
Currently the error has been forwarded to the internal cloud dev team.

1 Like

Any update in this issue? I have the same problem ;(

I believe the issue is due to the new Safe Mode Unity - Manual: Safe Mode
since 2020.2.
Unity Cloud Build doesn’t run batchmode with the -ignoreCompilerErrors flag which would override the default behavior which is to abort if compilation errors are encountered when importing. Unfortunately if the compiler errors in question are due to missing packages, this also means that NuGetForUnity doesn’t get a chance to run and download said packages because the build was already aborted.

We have solved this by adding the following to our pre-build scripts to restore the nuget packages. Notice the -ignoreCompilerErrors flag that ensures this will run even if compiler errors are encountered while importing.

"$UNITY_EXE" -quit -batchmode -ignoreCompilerErrors -projectPath "$WORKSPACE" -executeMethod NugetForUnity.NugetHelper.Restore```