使用脚本更新 CFBundleShortVersionString 在 Xcode 11 中出现错误 [英] update CFBundleShortVersionString with script gives error in Xcode 11
问题描述
我正在尝试使用此脚本更新主应用程序内的扩展应用程序.一般来说,当我使用 svn 提交时,我的主应用程序的版本会更新,现在我还需要更新扩展版本.我正在尝试使用以下脚本,但似乎出现错误.有什么想法吗?
I am trying to update with this script my extension app which is inside the main app. In general when i commit with svn, the version of my main app update, now i need to update the extension version also. I am trying to use the following script but seems it gives error. any idea?
这是一个例子:
version_number=$1
build_number=$2
#
echo "version_number is $version_number"
echo "build_number is $build_number"
pruvitInfoPlist="ServiceExtension/Info.plist"
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $version_number" $pruvitInfoPlis
错误:
> Build/file.rb:41: syntax error, unexpected unary-, expecting do or '{'
> or '(' /usr/libexec/PlistBuddy -c "Set CFBundleShortVersionSt...
> ^ Build/file.rb:41: syntax error, unexpected tGVAR, expecting end-of-input ...ersion_number" $pruvitInfoPlist ...
> ^~~~~~~~~~~~~~~~ Command PhaseScriptExecution failed with a nonzero
> exit code
推荐答案
我将在这里回答我的问题,也许可以帮助其他人.我用扩展中的脚本解决了这个问题.
I am going to Answer my question here maybe in can help someone else. I resolved the issue with script in extension.
plistFile = "#{ENV['BUILT_PRODUCTS_DIR']}/#{ENV['INFOPLIST_PATH']}"
`/usr/bin/plutil -convert xml1 "#{plistFile}"`
unless pl = Plist::parse_xml(plistFile)
puts "Could parse #{plistFile}"
exit
end
freshPlFile = "#{ENV['SOURCE_ROOT']}/ServiceExtension/Info.plist"
`/usr/bin/plutil -convert xml1 "#{freshPlFile}"`
unless freshPl = Plist::parse_xml(freshPlFile)
puts "Could parse #{freshPlFile}"
exit
end
version = pl["CFBundleShortVersionString"].gsub(/ \([a-f0-9 \/:]*\)/, '')
# keep only the major and minor version number and add the revision
version.gsub!(/([^\.]*)\.([^\.]*).*/, "\\1.\\2.#{revision}");
pl["CFBundleShortVersionString"] = version
pl["CFBundleVersion"] = Time.now.utc.strftime("%Y%m%d%H")
pl.save_plist(plistFile)
`/usr/bin/plutil -convert binary1 #{plistFile}`
puts "#{plistFile}:"
puts "CFBundleVersion = #{pl["CFBundleVersion"]}"
puts "CFBundleShortVersionString = #{pl["CFBundleShortVersionString"]}"
每次我提交时都会更新我的扩展程序和我的主应用程序.您还需要在主应用程序中添加此脚本.
every time i commit it update my extension and my main app. you need to add this script also in main app.
这篇关于使用脚本更新 CFBundleShortVersionString 在 Xcode 11 中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!