Xcode-Increment 内部版本号仅在 ARCHIVE 期间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9855955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:46:37  来源:igfitidea点击:

Xcode-Increment build number only during ARCHIVE?

xcodemacosxcode4xcode4.2osx-lion

提问by jsherk

I have found a few other posts that show how to add a script to increment the build number with a script:

我发现了一些其他帖子,这些帖子展示了如何添加脚本以使用脚本增加内部版本号:

Better way of incrementing build number?

增加内部版本号的更好方法?

Xcode project's "Build number"

Xcode 项目的“内部版本号”

Can Xcode insert the version number into a library's filename when building?

Xcode 可以在构建时将版本号插入到库的文件名中吗?

But what I want to do, is only increase the build number when I use ARCHIVE (both before and after).

但是我想要做的只是在我使用 ARCHIVE 时(之前和之后)增加内部版本号。

Example: If current build number is 21, then when I choose Product > Archive the build number will be increased to 22, it will go through its process of building and creating the Archive file with the build number of 22, and then when it is finished archiving, it will increase the build number to 23.

示例:如果当前内部版本号为 21,那么当我选择 Product > Archive 时,内部版本号将增加到 22,它将经历其构建和创建内部版本号为 22 的 Archive 文件的过程,然后当它完成归档后,它会将内部版本号增加到 23。

回答by lnafziger

Add the following script, as in the example listed in the first link that you posted, BUT do it twice. Once at the beginning of the build and once at the end:

添加以下脚本,如您发布的第一个链接中列出的示例,但要执行两次。一次在构建开始时,一次在构建结束时:

if [ $CONFIGURATION == Release ]; then
    echo "Bumping build number..."
    plist=${PROJECT_DIR}/${INFOPLIST_FILE}

# increment the build number (ie 115 to 116)
    buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
    if [[ "${buildnum}" == "" ]]; then
        echo "No build number in $plist"
        exit 2
    fi

    buildnum=$(expr $buildnum + 1)
    /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "${plist}"
    echo "Bumped build number to $buildnum"

else
    echo $CONFIGURATION " build - Not bumping build number."
fi

Many thanks to the authors of the questions that you have linked to in your question for the information that got me started on this answer!

非常感谢您在问题中链接到的问题的作者,这些问题让我开始回答这个问题!

回答by ccwasden

This is very similar to @Inafziger's answer, but a more concise set of code, with the added benefit that the check for "Release" is done with a checkbox in XCode rather than a runtime variable:

这与@Inafziger 的答案非常相似,但是一组更简洁的代码,还有一个额外的好处,即使用 XCode 中的复选框而不是运行时变量来检查“发布”:

enter image description here

在此处输入图片说明

Follow these instructions twice, dragging one to the beginning and one to the end(one to run before build and one to run after build):

按照这些说明两次,将一个拖到开头,一个拖到结尾(一个在构建前运行,一个在构建后运行):

# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run. 
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Ensure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
# 7. Check the checkbox "Run script only when installing"

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

See https://gist.github.com/sekati/3172554

https://gist.github.com/sekati/3172554

回答by orkoden

Xcode includes the command line tool agvtoolto increase version numbers. So you don't have to do everything manually with PListBuddy.

Xcode 包含增加版本号的命令行工具agvtool。因此,您不必使用PListBuddy.

xcrun agvtool next-version -all

xcrun agvtool next-version -all

increases your build number.

增加您的内部版本号。

xcrun agvtool new-marketing-version 2.0

xcrun agvtool new-marketing-version 2.0

sets a new user visible version number.

设置一个新的用户可见版本号。

See the full documentation for details.

有关详细信息,请参阅完整文档