nbannister

Unity post build minor version increment

Dec 6th, 2021
1,040
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using UnityEditor.Callbacks;
  5.  
  6. /// <summary>
  7. /// Automatically increment InternalSettingsInstance.versionBuild after an EXE is built.
  8. /// </summary>
  9. public class BuildPostprocessor {
  10.     [PostProcessBuildAttribute (1)]
  11.     public static void OnPostprocessBuild (BuildTarget target, string pathToBuiltProject) {
  12.  
  13.         // to update major or minor version, manually set it in Edit>Project Settings>Player>Other Settings>Version
  14.  
  15.         // this will also set Application.version which is readonly
  16.         string [] versionParts = PlayerSettings.bundleVersion.Split ('.');
  17.         if (versionParts.Length != 3 /*|| versionParts [2].ParseInt (-1) == -1*/) { //idk what this did, but it broke
  18.             Debug.LogError ("BuildPostprocessor failed to update version " + PlayerSettings.bundleVersion);
  19.             return;
  20.         }
  21.         // major-minor-build
  22.         versionParts [2] = (Int32.Parse( versionParts [2]) + 1).ToString ();
  23.         PlayerSettings.bundleVersion = string.Join (".", versionParts);
  24.     }
  25. }
RAW Paste Data