-
-
Save mbinna/4068616 to your computer and use it in GitHub Desktop.
Add the script include-version-info.sh into a new run script build phase of your application target. The build phase | |
should be located after the build phase "Copy Bundle Resources". |
# Use Xcode's copy of the Git binary | |
GIT=`xcrun -find git` | |
# Use the commit count as CFBundleVersion | |
GIT_COMMIT_COUNT=`${GIT} rev-list --count HEAD` | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${GIT_COMMIT_COUNT}" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}" | |
## Use the last annotated tag as CFBundleShortVersionString | |
GIT_TAG=`${GIT} describe --tags --always --dirty` | |
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${GIT_TAG}" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}" |
I had to remove this script temporarily as Xcode 11 GM Seed 2 (and everything before that) was clearing out the CFBundleVersion. I wasn't able to run my build on Jenkins as a result. It kept complaining about a missing bundle version even though it has a default value set that gets updated on the fly from this script. If anyone finds a workaround, I'd love to put this back.
Anyone find a fix for this? using xcrun agvtool next-version -all
was working for me in a build phase run script, but then when I added a Xcode server Bot everything just breaks for some reason.
@billburgess I guess that the updates for the default value on the fly actually interferes with the (strange) logic of Xcode. I, too, wanted to have the version params to be saved in a text file (I tried xcconfig
), but this didn't work reliably.
In the end, this script works for me when I put in Info.plist placeholders, like
<key>CFBundleShortVersionString</key>
<string>--</string>
<key>CFBundleVersion</key>
<string>--</string>
Unfortunately it seems like my
Info.plist
gets overwritten every time the app is finally run in XCode 11 beta. I tried variations ofBUILT_PRODUCTS_DIR
andTARGET_BUILD_DIR
(and adding them as input files) and I can get the plist value to change on build, but as soon as the app is run it is cleared. I've got the run script as the last task as well.Will be following this if anyone figures out how to make this work in 11 beta (w new build system).