I am trying to do the following:
Can I write a shell script for this?
It will be great if someone can guide me to achieve this.
Probably the simplest way is to use PlistBuddy. I have a Run Script phase that looks like this:
BUILD_NUMBER=`git rev-list HEAD --count` INFO_PLIST="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" if [ -f "$INFO_PLIST" ] ; then oldversion=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$INFO_PLIST"` fi if [ "$BUILD_NUMBER" != "$oldversion" ] ; then /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$INFO_PLIST" fi
(Note that starting with Xcode 6, you have to run this after the Copy Bundle Resources phase, because Info.plist
isn't copied to the target location until then and PlistBuddy would fail.)
Edit 01/17: Updated to avoid unnecessary copying or signing of targets. You don’t want to touch Info.plist unless something really changes, otherwise Xcode will treat it (and thus the target) as modified. Checking previous value CFBundleVersion
can significantly speed up builds — it saved me several seconds on noop build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With