如何自动递增捆绑版将于X code 4? [英] How to auto-increment Bundle Version in Xcode 4?

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

问题描述

我试图找出如何自动具有软件包版本号增量我的X code 4项目(用于临时和发布版本)。我发现一些脚本网上说声称要做到这一点,但我不确定是否将它们放在pre-行动或后操作。我也不能确定,我应该在的地方的plist什么价值;一些脚本将然后更改或变量?

这是我迄今为止尝试过的所有选项似乎不工作,所以任何帮助将大大AP preciated。

下面是最新的剧本我试图使用方法:

 的conf = $ {}配置
ARCH = $ {ARCHS:0:4}
#只增加设备和即席/ AppStore的版本版本号
如果[$ CONF =调试!]&功放;&安培; [$ CONF =释放!]&功放;&安培; [$拱!=386]
然后
buildPlist = $ {} INFOPLIST_FILE
buildVersion = $(在/ usr / libexec中/ PlistBuddy -c打印CFBuildVersion$ buildPlist)
buildNumber = $(在/ usr / libexec中/ PlistBuddy -c打印CFBuildNumber$ buildPlist)
buildNumber = $(($ buildNumber + 1))
在/ usr / libexec中/ PlistBuddy -c载:CFBuildNumber $ buildNumber$ buildPlist
在/ usr / libexec中/ PlistBuddy -c设置:CFBundleVersion $ buildVersion $ buildNumber$ buildPlist
在/ usr / libexec中/ PlistBuddy -c设置:CFBundleShortVersionString $ buildVersion $ buildNumber$ buildPlist
科幻


解决方案

1,设置CFBundleVersion到1.0.1或类似的东西X.X.X

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

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

 #!/ bin / sh的
#自动递增版本脚本
#设置CFBundleVersion到1.0.1第一!
#Perl的正则表达式打出一个版本号的最后一部分(即:1.1.1),并加一它
#如果你有一个内部版本号为3个以上的组件,添加一个\\。\\ D +入正则表达式的第一部分。
buildPlist = $ {} INFOPLIST_FILE
NEWVERSION =`在/ usr / libexec中/ PlistBuddy -c打印CFBundleVersion$ buildPlist|在/ usr /斌/ perl的-pe的/(\\ D + \\。\\ D + \\)(\\ D +)/ $ 1($ 2 + 1)/ eg'`
#echo $静态网页;
在/ usr / libexec中/ PListBuddy -c载:CFBundleVersion $ NEWVERSION$ buildPlist

4,运行shell:CP autoVersion.sh〜/文档/和chmod 777〜/文档/ autoVersion.sh

5,构建和放大器;好好享受。 :)

perl的code来源: https://gist.github.com/1436598

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

2, Add build phases to run shell script 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, run shell: cp autoVersion.sh ~/Documents/ and chmod 777 ~/Documents/autoVersion.sh

5, Build & Enjoy it. :)

perl code from: https://gist.github.com/1436598

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

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