Automated builds from outside of Unity

Hey,

I’m working on setting up some automated builds and I’d like to be able to do it without using the unity editor. Unfortunately , while I can set up a build inside of the editor, the following code throws a weird “ECall methods must be packaged into a system module” exception when I try running it using Visual Studio.

using System;
using UnityEngine;
using UnityEditor;
namespace AutomatedBuilder
{
	public class Builder
	{
		static int Main()
		{
			Builder buildUnityProject = new Builder();
			buildUnityProject.buildProject();
			
			return 0;
		}
		
		public Builder ()
		{
		}

		public void buildProject()
		{

            
			string[] scenes = new string[] {"Assets/Scenes/login.unity", "Assets/Scenes/MainRoom.unity", "Assets/Scenes/LoadScene.unity"};
			string filename = "Assets/GlobWorld2.unity3d";
            UnityEditor.BuildPipeline.BuildPlayer(scenes, filename, UnityEditor.BuildTarget.WebPlayer, UnityEditor.BuildOptions.Development);

		}
	}
}

Any ideas on what could be wrong? I’ve included the UnityEditor and UnityEngine libraries and the code works if I run it in the editor by creating a button and having the button run the buildProject() code. I’m guessing that there must be something else I need to include in my visual studio project but I can’t think of anything else.

you mean you get that exception when calling it from command line?

Because thats the only alternative to starting the editor, using the batchmode call to start a function from command line.

Unity can not be used as component in .NET projects, you can only put .net assemblies into unity

Not what I was trying to do but that’s what I should have been doing. There’s example code in the documentation for command line arguments that does almost exactly what I was trying to do. A couple quick copy pastes and everything works fine.

Thanks for pointing me in right direction.