Programmatically get version of Unity installed on a machine

Hello,

I am wondering if there is any way to know the version of Unity installed on a machine (PC or Mac). We have multiple build machines constantly building our game and sometimes we want to be able to build it on a specific version of Unity - for example 3.5 beta. At the moment we do this by installing Unity on a new build machine and then add it to our Continuous Integration server. For each build new build agent we have to enter the Unity version it supports automatically. This is a bit tidious and we would like our CI server to be able to work out what version of Unity is installed on a machine automatically.

Is there a file somewhere in Unity’s installation folder that would give me the information I need?

Thanks,

Clem

Currently you can obtain some version information this way:

using UnityEditorInternal;
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
Debug.Log(
  "Unity version      = " + Application.unityVersion + "\n" +
  "Full Unity version = " + InternalEditorUtility.GetFullUnityVersion() + "\n" +
  "Version date       = " + dt.AddSeconds(InternalEditorUtility.GetUnityVersionDate())
);

These days it’s surely easiest to use the UnityHub, which finally got a command line interface.
It’s easy to enumerate editors installed through the hub, and to install any version if you know the changeset hash, like unityhub://2019.2.5f1/9dace1eed4cc

Check the help screen with (on Windows)
"Unity Hub.exe" -- --headless help

Have you checked out the version defines? I’m not sure if you’re looking for a runtime check or a compile time check, or just a setting?

More examples here.

Check for updates. It will tell you your current version number.

generate an editor script that includes a #if define, get the result, set an editor pref, then purge the dummy script. I know it’s clunky but it’ll work.

Pretty old post, but for those who see this, UnitySetup is a OSS PowerShell module that supports automating Unity and is super useful for build machines. You can use it to discover all the versions available on a machine and even install new components or versions. You can also use it to automate the Unity editor and register/return licenses.

We use it’s PowerShell DSC resources to automated our entire build infrastructure’s use of Unity.

Another way:

 Unity.exe -batchmode -nographics -quit -version

Prints (e.g.):

6000.0.28f1