I don't know which way is the best, but I will post Apple's answer just in case anybody is searching for it...
According to this Apple's Q&A post:
Automating Version and Build Numbers Using agvtool
The version and build number keys respectively specify the marketing and internal versions of your application. agvtool is a command-line tool that allows you to automatically increment these numbers to the next highest number or to a specific number.
The build number identifies an unreleased or released version of your application. It is stored in your application’s Info.plist as CFBundleVersion
(Bundle version).
You must complete the following steps in your Xcode project:
- Enable agvtool
Navigate to the Build Settings pane of your target, then update it for all your build configurations as follows:
- Set Current Project Version to a value of your choosing.
Your Xcode project data file, project.pbxproj, includes a CURRENT_PROJECT_VERSION
(Current Project Version) build setting, which specifies the current version of your project. agvtool searches project.pbxproj for CURRENT_PROJECT_VERSION
. It continues running if CURRENT_PROJECT_VERSION
exists and stops running, otherwise. Its value is used to update the build number.
- Set Versioning System to Apple Generic.
By default, Xcode does not use any versioning system. Setting Versioning System to Apple Generic ensures that Xcode will include all agvtool-generated version information in your project.
- Set up your version and build numbers
agvtool searches your application’s Info.plist for your version and build numbers. It updates them if they exist and does nothing, otherwise. Make sure that the CFBundleVersion
(Bundle version) and CFBundleShortVersionString
(Bundle versions string, short) keys exist in your Info.plist as seen in the image below:
Quit Xcode, then navigate to the directory containing your .xcodeproj project file in the Terminal application before running any of the following commands. The .xcodeproj project file contains project.pbxproj, which is used by agvtool. (This is the part you can run in a script instead of command line.)
Updating the Version Number
To update the version number to a specific version, run
xcrun agvtool new-marketing-version <your_specific_version>
Ex: Update the version number to 2.0
xcrun agvtool new-marketing-version 2.0
Updating the Build Number
To automatically increment your build number, run
xcrun agvtool next-version -all
To set the build number of your application to a specific version, run
xcrun agvtool new-version -all <your_specific_version>
Ex: Set the build number to 2.6.9
xcrun agvtool new-version -all 2.6.9
Bonus:
To view the current version number, run
xcrun agvtool what-marketing-version
To view the current build number, run
xcrun agvtool what-version
tools
, right next to the.xcodeproj
. – SterneCFBundleVersion
includes a decimal, e.g.1.0
. Shell scripts can only add integers with the raw+
operator. Change to plain1
and it will work fine. – Schweiz.sh
/.scpt
file executable. This can be done by runningchown +x /path/to/file.sh
. – Dunkle