Skip to content

Instantly share code, notes, and snippets.

@mbinna
Last active November 12, 2021 20:59
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbinna/4068616 to your computer and use it in GitHub Desktop.
Save mbinna/4068616 to your computer and use it in GitHub Desktop.
Include Version Info from Git into Info.plist at build time
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}"
@alexcohn
Copy link

@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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment