how to get XCode to add build date & time to Info.plist file

本小妞迷上赌 提交于 2019-11-30 00:27:29

The code in Michael's answer is incorrect or no longer up to date. The version below fixes an error in the set syntax and also supports build paths with spaces in them.

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" builddate=`date` if [[ -n "$builddate" ]]; then     # if BuildDateString doesn't exist, add it     /usr/libexec/PlistBuddy -c "Add :BuildDateString string $builddate" "${infoplist}"     # and if BuildDateString already existed, update it     /usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "${infoplist}" fi 

Note: This change was submitted as an edit but got rejected and I don't yet have enough reputation to post a comment on his answer...

Michael Dautermann

Ahhhh, I should have spent another 30 minutes (on top of the 2 hours I had already wasted) and looked at the answers for this question before posting my own:

Insert Subversion revision number in Xcode

This post-action script does the trick and works for me:

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" builddate=`date` if [[ -n "$builddate" ]]; then     # if BuildDateString doesn't exist, add it     /usr/libexec/PlistBuddy -c "Add :BuildDateString string $builddate" "${infoplist}"     # and if BuildDateString already existed, update it     /usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "${infoplist}" fi 

As you can see, it's doing a bit of a hack there (adding it if it doesn't exist; setting it right afterwards).

If anyone can suggest a solution using the "defaults write" method above (which I think might be better supported than "PlistBuddy"), I'd be thrilled to find out (and of course I'll accept and use that superior answer, too).

I am using your exact code, but within the pre-action instead of the post-action, and the info.plist within the built product correctly reports the build date. In other words, you have to customize your info.plist before copying it into the built product, which sounds reasonable to me.

By the way, thanks for the suggestion, it's pretty clever and useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!