Archive

Posts Tagged ‘revision’

How to add a subversion build number to your Xcode project

August 19th, 2009 No comments
Major version and SVN revision number used as build number

Major version and SVN revision number used as build number

Using the SVN revision number can be very useful. For example when publishing beta versions, or just being able to track your builds in more detail.

Create an empty  file called “buildnumber.xcconfig” in you project resource folder.

Double click your build target. Go to the build tab. in the dropdown on the bottom right, select Based On: buildnumber.
Scroll down and under the header Versioning change the Current Project Version to ${BUILD_NUMBER}.

Open your Info.plist file. Add these lines:
<key>CFBundleVersion</key>
<string>${BUILD_NUMBER}</string>
<key>CFBundleShortVersionString</key>
<string>Version MAJORVERSION</string>

You can enter anything you want for CFBundleVersion. This will be the major version name.
Now expand your target until you see Run Script. Right click it and go to Add>New Build Phase>New Run Script Build Phase.
Enter this script in the script window and change the project directory to match yours.

export TEMP=`/usr/bin/svnversion -nc ${PROJECT_DIR} | /usr/bin/sed -e ‘s/^[^:]*://;s/[A-Za-z]//’`
echo “BUILD_NUMBER = $TEMP” > ${PROJECT_DIR}/buildnumber.xcconfig

After this you should be getting “Version MAJORVERSION (xx)” string in your application’s about window with xx being the current SVN revision. You might need to clean all targets and rebuild your application for the changes to kick in.