Build Player from Command Line

I’ve made a batch file with the following command line:

"C:\Program Files (x86)\Unity\Editor\Unity.exe" -batchMode -quit -nographics -projectPath C:\project -executeMethod AutoBuilder.PerformBuild

Which calls the following method:

static void PerformBuild ()
{

       	string[] scenes = { "1.unity","2.unity","3.unity","4.unity","5.unity" };
		BuildPipeline.BuildPlayer(scenes,"win.exe",BuildTarget.StandaloneWindows,BuildOptions.None);
		BuildPipeline.BuildPlayer(scenes,"osx.app",BuildTarget.StandaloneOSXUniversal,BuildOptions.None);
  	    BuildPipeline.BuildPlayer(scenes,"WebPlayer.unity3d",BuildTarget.WebPlayerStreamed,BuildOptions.None);
		scenes = null;

}

It does build the three players but unfortunately it only compiles one of them.

Is there anyway to force compile before building? Am I missing something?

EDIT:

I tried separating in different functions and different calls and the same thing happens, I get the 3 builds but only one has been compiled, the other 2 act as if there were no changes to the code.

"C:\Program Files (x86)\Unity\Editor\Unity.exe" -batchMode -quit -nographics -projectPath C:\project -executeMethod AutoBuilder.PerformWebBuild
"C:\Program Files (x86)\Unity\Editor\Unity.exe" -batchMode -quit -nographics -projectPath C:\project -executeMethod AutoBuilder.PerformWindowsBuild
"C:\Program Files (x86)\Unity\Editor\Unity.exe" -batchMode -quit -nographics -projectPath C:\project -executeMethod AutoBuilder.PerformWebBuild

Presumably, you can use EditorUserBuildSettings.SwitchActiveBuildTarget to set the active build target before you build. I haven’t tried it but I came across the method and thought about your problem :slight_smile:

If you place the command in a command file, eg. “compileall.cmd” and then make a function for each platform.

Then you can auto compile all three just by clicking on the CMD file.

would that be enough?