Automatic build numbering increase with xCode

I had this problem some days ago where i wanted to automatically increase the build number of my Application in xCode, every time that i actually made a new build. xCode comes with a tool called agvtool which is supposed to fill this gap, but the main problem with this is that it needs the project to be actually closed, for some reason that i certainly ignore.

After some searches, i finished at this interesting post by Chris Hanson, but this was not exactly what i wanted to do, again, i wanted a simple approach to increase the build number with every build.

So this is what i did.

First I created a new configuration settings file in xCode, as shown below.

Creating a new Configuration Settings File in xCode

Creating a new Configuration Settings File in xCode

After this, i ended up with an empty configuration file, so i added the following inside it:


xCode uses this variable to store your application’s build number, so we are going to tell it to use this file in order to get the value for the CURRENT_PROJECT_VERSION variable.

Go to your target’s properties, be sure to select All configurations and All Settings, then base your target’s config in your newly created version.xcconfig file, and set the version variable to our new version variable as shown below:

Configuring the Target to use the new variable in the version.xcconfig file.

Configuring the Target to use the new variable in the version.xcconfig file.

After all this is done, all you have to do is create a new “Run Script” build phase, and place the following inside it:

NEW_VERSION=`cat "$SRCROOT/version.xcconfig" | awk '/CURRENT_PROJECT_VERSION/ { print $3 + 1 }'`
touch "$SRCROOT/version.xcconfig"

Obviously, if you changed the file or variable names, you will have to adapt the script as needed.
Now, every time you build the app, the build number is automatically increased by one, and included in your application’s plist file as shown below:

Build number being shown in the built app.

Build number being shown in the built app.

A whole thanks goes to the guys at #macdev on freenode Diabolik and KonaBlend who helped with the bash scripting!

Be Sociable, Share!

Related posts:

No related posts.

One Response to “Automatic build numbering increase with xCode”

  1. hey there and thank you on your information ? I’ve certainly picked up anything new from proper here. I did on the other hand expertise a few technical points the usage of this web site, as I skilled to reload the web site lots of occasions previous to I could get it to load properly. I were puzzling over if your web hosting is OK? Now not that I am complaining, but sluggish loading circumstances times will often impact your placement in google and could injury your high quality score if ads and marketing with Adwords. Anyway I am adding this RSS to my e-mail and could glance out for much more of your respective interesting content. Ensure that you update this once more very soon..

    by website builder, April 9th, 2013 at 5:43 pm