In Xcode, updating a project version couldn’t be easier. Just head over to the Info section of the target settings and modify the Version and Build fields:
There are other situations which may require some form of automation for this process. For example, when working continuous and build integration tools or when the project contains multiple targets.
The agvtool is a command-line tool that allows you to automatically increment or update the Version and Build number of a project or target.
First, we need to configure the project to use Apple Generic Versioning. Note: this can be done both on target or project level.
Go to Build Settings and find the Versioning section showing the Current Project Version and Versioning System parameters:
Set the value for Current Project version to the current build number of your project, for example 1.
Set the value for Versioning System to “Apple Generic”.
Now, from the command-line we can execute commands to retrieve or update the project and target versions:
- Show the current build number of the project:
$ xcrun agvtool what-version
- Show the current version of the project
$ xcrun agvtool what-marketing-version
- Update the build number
$ xcrun agvtool new-version -all 1
- Update the version number
$ xcrun agvtool new-marketing-version 1.116
The agvtool also supports scenarios to automatically determine the “next” version as well as other configuration options. More information is of course availablie in the docs.