Command line build failing but works great when run from the editor.

I’m working on setting up automated builds for a Unity 5 project and I’ve made some progress building within Unity but now that I’m moving on to building from the command line I’m running into a snag and hopeful I can get some help.

To start I’ve made a static class and added some menu items to Unity for single-click builds. Some sample code:

using UnityEngine;
using UnityEditor;

namespace Builds
{
    public static class AutomatedBuilds
    {
        private static string _buildPath = "mypath";
        private static string _appName = "myapp";
        private static string _buildNumber = "0.0.0";

        [MenuItem("Build Tools/Windows x64 Debug", false, 0)]
        public static void BuildWindows_x64_Debug()
        {
            BuildPipeline.BuildPlayer(
                _levels,
                string.Format("{0}/{1}/{2}_{3}_{4}.exe", _buildPath, "win", _appName, "Debug", _buildNumber),
                BuildTarget.StandaloneWindows64,
                BuildOptions.AllowDebugging
            );
        }
    }
}

After this script gets compiled by Unity I get a menu item called “Build Tools” with a command called “Windows x64 Debug”. Clicking this invokes the build and it all works great: my build gets made and I can run it no problem.

My next step is to run this all from the command line. The command I’m running looks like:

'"C:\\Program Files\\Unity\\Editor\\Unity.exe" -projectPath E:\path	o\UnityProject -batchMode -executeMethod AutomatedBuilds.BuildWindows_x64_Debug -logFile E:\path	o\BuildLog\build.log -nographics -quit'

This also runs but I get the following output in the console:

Aborting batchmode due to failure:
Scripts have compiler errors.

Since that’s a vague error message I’ve checked the build.log file generated with the command and there is a ton of stuff in there but it all looks like general build stuff except for this bit toward the end:

-----CompilerOutput:-stderr----------

Assets/Scripts/Test/TestUI.cs(17,27): error CS0234: The type or namespace name `Dropdown' does not exist in the namespace `UnityEngine.UI'. Are you missing an assembly reference?

The file in question looks like:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Assertions;

using GameEvents;
using DataContracts;

public class TestUI : MonoBehaviour {

    public InputField[] SetCardFields;
    public GameObject TestPanel;

    public GameObject DeckView;
    public GameObject TestCardPrefab;

    [Header("Charm Setter")]
    public Dropdown CharmSelectionDropdown; // <-- THIS IS THE LINE CALLED OUT IN THE LOG

    // more but you get the idea

I’ve confirmed that Dropdown is a Unity UI class so it should be good (also it compiles when running Unity).

I’m running Unity 5.2.2f1 64 bits on Windows 10 x64.
I have a similar script (though the project doesn’t currently use Unity UI) that builds a different project without issues from the command line.

Ideally I need to stick with 5.2.2f1 as I’m working with a team and cannot just upgrade on a whim. If this is a known bug in 5.2.2f1 then an upgrade is probably called for but a Google search reveals nothing.

So, my question: why does Unity crash when building from the command line but not from within the Unity application itself? What are steps can I take to get to the bottom of this?

Turns out the problem was that I was pointing to the wrong version of Unity. I have Unity 5.2.2f1 installed at “C:\Program Files\Unity5\Editor\Unity.exe” while my script was pointed at “C:\Program Files\Unity\Editor\Unity.exe”.

I had the same problem you did, but only had a single version of Unity installed. In my case, getting rid of the -nographics option fixed my problem.

i too made same mistake…