How to set CFBundleVersion in a script?

Setting CFBundleVersion in a Run Script Build Phase (using PlistBuddy or agvtool) no longer works since Info.plist is being auto-generated for newly created Xcode projects. So what is the recommended way to achieve this now?

I also have this issue

I have same issue. Can only find options that do not work on Xcode 15.4

I have found a workaround for this problem by letting Xcode generate the Info.plist, then ignoring the CFBundleVersion key that it generates. I then ALSO supply a minimal explicit Info.plist file in Build Settings -> Packaging that only contains a single user defined MyBundleVersion key:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>MyBundleVersion</key>
	<string>68</string>
</dict>
</plist>

Then I use PlistBuddy to increment MyBundleVersion instead of CFBundleVersion. and then reference the MyBundleVersion key in code:

let myBundleVersion = Bundle.main.infoDictionary?["MyBundleVersion"] as? String

How to set CFBundleVersion in a script?
 
 
Q