Xcode 项目的“内部版本号”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7371345/
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
Xcode project's "Build number"
提问by Peter V
What is a Build number and what is its use? Is it the same as version number?
什么是内部版本号以及它的用途是什么?和版本号一样吗?
采纳答案by cdasher
Additionally, if you add CFBuildDate as a string and CFBuildNumber as a string into your info.plist, the following shell script (when added to your run script build phase /bin/bash will automatically update your build number and date:
此外,如果您将 CFBuildDate 作为字符串添加并将 CFBuildNumber 作为字符串添加到您的 info.plist 中,以下 shell 脚本(添加到您的运行脚本构建阶段 /bin/bash 将自动更新您的构建编号和日期:
# Auto Increment Version Script
buildPlist=${INFOPLIST_FILE}
CFBuildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
CFBuildNumber=$(($CFBuildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $CFBuildNumber" $buildPlist
CFBuildDate=$(date +%Y%m%d%H%M%S)
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" $buildPlist
回答by rmartinsjr
I'm using Xcode 4.3.3 (4E3002) and managed to have build number (CFBundleVersion) automatically increased every build with the following steps:
我正在使用 Xcode 4.3.3 (4E3002) 并设法通过以下步骤自动增加内部版本号 (CFBundleVersion):
- Select the menu item Product/Edit Scheme... (Command+<)
- Expanded the Build phase
- Select Pre-actions
- Clicked on the plus sign to add "New Run Script Action"
- Entered "/bin/bash" as the "Shell"
- Select one of the targets in "Provide build settings from"
Entered the following code:
buildPlist=$SRCROOT/$INFOPLIST_FILE PlistBuddy="/usr/libexec/PlistBuddy" CFBundleVersion=`$PlistBuddy -c "Print CFBundleVersion" $buildPlist` CFBundleVersion=$(($CFBundleVersion + 1)) $PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" $buildPlist
- 选择菜单项产品/编辑方案... (Command+<)
- 扩展了构建阶段
- 选择前置动作
- 单击加号添加“新建运行脚本操作”
- 输入“/bin/bash”作为“Shell”
- 在“提供构建设置自”中选择目标之一
输入以下代码:
buildPlist=$SRCROOT/$INFOPLIST_FILE PlistBuddy="/usr/libexec/PlistBuddy" CFBundleVersion=`$PlistBuddy -c "Print CFBundleVersion" $buildPlist` CFBundleVersion=$(($CFBundleVersion + 1)) $PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" $buildPlist
Have fun!
玩得开心!
回答by jemmons
Many people use the build number to track the total number of times a project is "built" (simply compiled for small projects, maybe some more involved process for larger ones).
许多人使用构建号来跟踪项目“构建”的总次数(仅为小项目编译,对于较大的项目可能需要一些更复杂的过程)。
The build number is an absolute value incremented every build. A version number, on the other hand, is an arbitrary "label" or "tag" used as shorthand for a specific build number.
构建编号是每次构建都会增加的绝对值。另一方面,版本号是任意“标签”或“标记”,用作特定内部版本号的简写。
So say you've built your project 123 times, your build number is "123", but you might decide to refer to that as "version 1.0" for simplicity sake. If you build another 20 times to fix a bug, your build number is 143, but your version is "1.01" or "1.1" or whatever you decide to name it.
因此,假设您已经构建了 123 次项目,您的构建号是“123”,但为了简单起见,您可能决定将其称为“1.0 版”。如果你再构建 20 次来修复一个错误,你的构建号是 143,但你的版本是“1.01”或“1.1”或任何你决定命名的。
I've also seen projects that base their build numbers on source control. So a CVS/SVN team might use the revision number as their build number. I've also seen git projects that use the SHA of the latest commit as a build number (although some management tools assume the build number is an incremental value — and obviously in the case of SHAs, it's not).
我还看到了基于源代码管理的构建编号的项目。因此,CVS/SVN 团队可能会使用修订号作为他们的内部版本号。我还看到 git 项目使用最新提交的 SHA 作为内部版本号(尽管一些管理工具假设内部版本号是一个增量值——显然在 SHA 的情况下,它不是)。
回答by Bdebeez
The Build number is an internal number that indicates the current state of the app. It differs from the Version number in that it's typically not user facing and doesn't denote any difference/features/upgrades like a version number typically would.
内部版本号是一个内部编号,表示应用程序的当前状态。它与版本号的不同之处在于它通常不是面向用户的,并且不像通常的版本号那样表示任何差异/功能/升级。
Think of it like this:
可以这样想:
- Build (CFBundleVersion): The number of the build. Usually you start this at 1 and increase by 1 with each build of the app. It quickly allows for comparisons of which build is more recent and it denotes the sense of progress of the codebase. These can be overwhelmingly valuable when working with QA and needing to be sure bugs are logged against the right builds.
- Marketing Version (CFBundleShortVersionString) - The user-facing number you are using to denote this version of your app. Usually this follows a Major.minor version scheme (e.g. MyAwesomeApp 1.2) to let users know which releases are smaller maintenance updates and which are big deal new features.
- 构建(CFBundleVersion):构建的编号。通常你从 1 开始,并随着应用程序的每个构建增加 1。它可以快速比较哪个构建是较新的,它表示代码库的进度感。在使用 QA 并需要确保针对正确的构建记录错误时,这些可能非常有价值。
- 营销版本 (CFBundleShortVersionString) - 用于表示此应用版本的面向用户的编号。通常这遵循 Major.minor 版本方案(例如 MyAwesomeApp 1.2),让用户知道哪些版本是较小的维护更新,哪些是重要的新功能。
To use this effectively in your projects, Apple provides a great tool called agvtool. It allows you to easily set both the build number and the marketing version. It is particularly useful when scripting (for instance, easily updating the build number on each build or even querying what the current build number is). It can even do more exotic things like tag your SVN for you when you update the build number.
为了在您的项目中有效地使用它,Apple 提供了一个很棒的工具,称为 agvtool。它允许您轻松设置内部版本号和营销版本。它在编写脚本时特别有用(例如,轻松更新每个构建的构建编号,甚至查询当前构建编号是什么)。它甚至可以做更多奇特的事情,例如在您更新内部版本号时为您标记 SVN。
To use it:
要使用它:
- Set your project in Xcode, under Versioning, to use "Apple Generic".
- In terminal
- agvtool new-version 1 (set the Build number to 1)
- agvtool new-marketing-version 1.0 (set the Marketing version to 1.0)
- 在 Xcode 中的 Versioning 下设置您的项目以使用“Apple Generic”。
- 在终端
- agvtool new-version 1(将版本号设置为 1)
- agvtool new-marketing-version 1.0(将营销版本设置为 1.0)
See the man page of agvtoolfor a ton of good info
请参阅agvtool 的手册页以获取大量好的信息
回答by Roger
If you want to use a DATE field for CFBuildDate, use:
如果要为 CFBuildDate 使用 DATE 字段,请使用:
# get UTC date
CFBuildDate=$(date -u +"%a %b %d %T GMT %Y")
btw great tip from cdasher
顺便说一句,来自 cdasher 的重要提示
回答by Finn Larsen
Build Number is for minor updates(usually get pretty high 1 at the beginning and can end at 1000), ex: if you change a couple lines of code but doesn't change the logic or make new features in your update. Version Number is for rather large updates ex: new features in your app. Then you can change it from 1.8 to 2.0.
内部版本号用于次要更新(通常在开始时获得相当高的 1 并且可以在 1000 结束),例如:如果您更改了几行代码但没有更改逻辑或在您的更新中创建新功能。版本号用于相当大的更新,例如:应用程序中的新功能。然后您可以将其从 1.8 更改为 2.0。
回答by Kiran
This works for me in Xcode 6:
这在 Xcode 6 中对我有用:
cd ${SOURCE_ROOT}
buildPlist=${SOURCE_ROOT}/${PROJECT_NAME}/${PROJECT_NAME}-Info.plist
PlistBuddy="/usr/libexec/PlistBuddy"
buildNumber=`git rev-list HEAD --count`
buildNumber=$(($buildNumber + 1))
$PlistBuddy -c "Set :CFBundleVersion $buildNumber" $buildPlist
回答by edwardmp
This works in Xcode 6 and also modifies the dSYM info dictionary, only when archiving:
这适用于 Xcode 6 并且还修改了 dSYM 信息字典,仅在归档时:
if [ "${CONFIGURATION}" = "Release" ]; then
buildPlist="${SOURCE_ROOT}/${PROJECT_NAME}/${PROJECT_NAME}-Info.plist"
PlistBuddy="/usr/libexec/PlistBuddy"
CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}")
CFBundleVersion=$(($CFBundleVersion + 1))
$PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "$buildPlist"
$PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "$INFOPLIST_FILE"
$PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "${DWARF_DSYM_FOLDER_PATH}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
fi
回答by Gennadiy Ryabkin
CFBundleVersion(Bundle version) - aka Marketing version
which will be shown on your product's page on Appstore.
CFBundleVersion(捆绑版本)- 也Marketing version
就是将显示在 Appstore 上您的产品页面上。
CFBundleShortVersionString(Bundle versions string, short) - bundle number, usually used as a minor version which can be seen by TestFlight users only
CFBundleShortVersionString(Bundle versions string, short) - 包号,通常用作只有 TestFlight 用户可以看到的次要版本
Here's how can you get them in Swift (4+)
programmatically:
以下是如何以Swift (4+)
编程方式获取它们:
let buildNumber = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String,
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")
I needed the marketing version in my shell script once and here's how I got it using xcode build tools
:
我曾经在我的 shell 脚本中需要营销版本,这是我使用它的方法xcode build tools
:
xcodebuild -showBuildSettings -project ${SDK_PROJECT} | sed '1d;s/^ *//;s/"/\"/g;s/ = \(.*\)/=""/;s/ = /=/;s/UID.*//' > xcodebuild-env.tmp
source xcodebuild-env.tmp
echo "${MARKETING_VERSION}"