如何在 Xcode 4 中自动增加捆绑版本? [英] How to auto-increment Bundle Version in Xcode 4?

查看:22
本文介绍了如何在 Xcode 4 中自动增加捆绑版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何在我的 Xcode 4 项目中自动增加 Bundle 版本号(用于临时和发布版本).我在网上找到了一些声称要执行此操作的脚本,但我不确定是将它们放在操作前"还是操作后"中.我也不确定应该在 plist 中放置什么值;脚本将更改的数字或变量?

I am trying to figure out how to have the Bundle version number increment automatically in my Xcode 4 project (for ad-hoc and release builds). I found some scripts online that purport to do this but I am unsure of whether to place them in the "Pre-actions" or "Post-actions". I also am unsure what value I should place in the plist; a number that the script will then change or a variable?

到目前为止我尝试过的所有选项似乎都不起作用,因此我们将不胜感激.

All the options that I have tried thus far do not seem to work so any help would be greatly appreciated.

以下是我尝试使用的最新脚本:

Below is the most recent script I was attempting to use:

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, Set CFBundleVersion to 1.0.1 or something like x.x.x

1, Set CFBundleVersion to 1.0.1 or something like x.x.x

2、添加构建阶段来运行shell脚本autoVersion.sh

2, Add build phases to run shell script autoVersion.sh

3、保存下面的脚本名为autoVersion.sh

3, save below script named 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/and chmod 777 ~/Documents/autoVersion.sh

4, run shell: cp autoVersion.sh ~/Documents/ and chmod 777 ~/Documents/autoVersion.sh

5、构建&好好享受.:)

5, Build & Enjoy it. :)

perl 代码来自:https://gist.github.com/1436598

这篇关于如何在 Xcode 4 中自动增加捆绑版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆