我试图弄清楚如何在我的Xcode 4项目中自动增加 bundle 软件版本号(适用于临时版本和发行版)。我在网上找到了一些声称可以做到这一点的脚本,但是我不确定是否将它们放在“ Action 前”或“ Action 后”中。我也不确定应该在plist中放置什么值;脚本将要更改的数字还是变量?
到目前为止,我尝试过的所有选项似乎都无效,因此,我们将不胜感激。
以下是我尝试使用的最新脚本:
conf=${CONFIGURATION}
arch=${ARCHS:0:4}
# Only increase the build number on Device and AdHoc/AppStore build
if [ $conf != "Debug" ] && [ $conf != "Release" ] && [ $arch != "i386" ]
then
buildPlist=${INFOPLIST_FILE}
buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBuildVersion" $buildPlist)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildVersion.$buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildVersion.$buildNumber" $buildPlist
fi
最佳答案
1,将CFBundleVersion设置为1.0.1或类似x.x.x的文件
2,添加构建阶段以运行shell脚本autoVersion.sh
3,保存下面名为autoVersion.sh的脚本
#!/bin/sh
# Auto Increment Version Script
# set CFBundleVersion to 1.0.1 first!!!
# the perl regex splits out the last part of a build number (ie: 1.1.1) and increments it by one
# if you have a build number that is more than 3 components, add a '\.\d+' into the first part of the regex.
buildPlist=${INFOPLIST_FILE}
newVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.)(\d+)/$1.($2+1)/eg'`
#echo $newVersion;
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$buildPlist"
4,运行shell:cp autoVersion.sh〜/Documents/和chmod 777〜/Documents/autoVersion.sh
5,建立并享受它。 :)
Perl代码来自:https://gist.github.com/1436598