Xcode 4:使用Git repo commit版本在每个构建上更新CFBundleVersion

我正在将 Xcode 4与 Git结合使用,并希望在每个版本的Info.plist中增加CFBundLeversion.密钥CFBundLeversion的值应更新为我对Git存储库的最后一次提交的数量.

我发现that python脚本运行良好,但遗憾的是它没有更新我的Xcode项目中的Info.plist – 它只是更新了“BUILT_PRODUCTS_DIR”中的Info.plist.

有没有人知道如何让Xcode 4获取最新提交的版本并将该信息放入项目的Info.plist中?

谢谢!

解决方法

版本字符串必须是格式[xx].[yy].[zz]其中x,y,z是数字.

我通过使用git标签为x和y(例如0.4)提供有意义的标记号来处理这个问题,然后通过脚本构建阶段,z获取自git describe返回的自上一个标记以来的提交数.

这是我从this one改编的脚本.它可以作为构建阶段直接添加到目标(shell是/usr/bin/env ruby​​):

# add git tag + version number to Info.plist
version = `/usr/bin/env git describe`.chomp

puts "raw version "+version
version_fancy_re = /(\d*\.\d*)-?(\d*)-?/
version =~ version_fancy_re
commit_num = $2
if ( $2.empty? )
commit_num = "0"
end
fancy_version = ""+$1+"."+commit_num
puts "compatible: "+fancy_version

# backup
source_plist_path = File.join(ENV['PROJECT_DIR'],ENV['INFOPLIST_FILE'])
orig_plist = File.open( source_plist_path,"r").read;
File.open( source_plist_path+".bak","w") { |file| file.write(orig_plist) }

# put in CFBundLeversion key
version_re = /([\t ]+<key>CFBundLeversion<\/key>\n[\t ]+<string>).*?(<\/string>)/
orig_plist =~ version_re
bundle_version_string = $1 + fancy_version + $2
orig_plist.gsub!(version_re,bundle_version_string)

# put in CFBundleShortVersionString key
version_re = /([\t ]+<key>CFBundleShortVersionString<\/key>\n[\t ]+<string>).*?(<\/string>)/
orig_plist =~ version_re
bundle_version_string = $1 + fancy_version + $2
orig_plist.gsub!(version_re,bundle_version_string)

# write
File.open(source_plist_path,"w") { |file| file.write(orig_plist) }
puts "Set version string to '#{fancy_version}'"

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...