版本与在 Xcode 中构建 [英] Version vs build in Xcode

查看:19
本文介绍了版本与在 Xcode 中构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Xcode 3 开发的应用程序,最近开始使用 Xcode 4 进行编辑.在目标摘要中,我有 iOS 应用程序目标表单,其中包含以下字段:标识符、版本、构建、设备和部署目标.版本字段为空,构建字段为 3.4.0(这与我还在使用 Xcode 3 进行编辑时的应用版本相匹配).

I have an app that I developed with Xcode 3 and recently started editing with Xcode 4. In the target summary I have the iOS application target form with fields: identifier, version, build, devices, and deployment target. The version field is blank and the build field is 3.4.0 (which matches the version of the app from when I was still editing with Xcode 3).

我的问题是:

  1. 版本和构建字段有什么区别?

  1. What is the difference between the version and build fields?

为什么我升级到 Xcode 4 后版本字段为空?

Why was the version field blank after I upgraded to Xcode 4?

推荐答案

Apple 对这些字段进行了重新排列/重新利用.

Apple sort of rearranged/repurposed the fields.

展望未来,如果您查看应用程序目标的信息选项卡,您应该使用Bundle versions string, short"作为您的版本(例如 3.4.0)和Bundle version"作为您的 Build(例如,500 或 1A500).如果您没有看到它们,您可以添加它们.这些将映射到摘要"选项卡上的正确版本和构建文本框;它们是相同的值.

Going forward, if you look on the Info tab for your Application Target, you should use the "Bundle versions string, short" as your Version (e.g., 3.4.0) and "Bundle version" as your Build (e.g., 500 or 1A500). If you don't see them both, you can add them. Those will map to the proper Version and Build textboxes on the Summary tab; they are the same values.

查看信息选项卡时,如果您右键单击并选择显示原始键/值,您将看到实际名称为CFBundleShortVersionString(版本)和<代码>CFBundleVersion(构建).

When viewing the Info tab, if you right-click and select Show Raw Keys/Values, you'll see the actual names are CFBundleShortVersionString (Version) and CFBundleVersion (Build).

版本通常用于您在 Xcode 3 中使用它的方式.我不确定您在什么级别上询问版本/构建差异,所以我会从哲学上回答.

The Version is usually used how you appear to have been using it with Xcode 3. I'm not sure on what level you're asking about the Version/Build difference, so I'll answer it philosophically.

有各种各样的方案,但一种流行的是:

There are all sorts of schemes, but a popular one is:

{MajorVersion}.{MinorVersion}.{Revision}

{MajorVersion}.{MinorVersion}.{Revision}

  • 主要版本 - 主要更改、重新设计和功能变化
  • 次要版本 - 次要改进,增加了功能
  • 修订版 - 错误修复的补丁号
  • Major version - Major changes, redesigns, and functionality changes
  • Minor version - Minor improvements, additions to functionality
  • Revision - A patch number for bug-fixes

然后单独使用 Build 来表示一个版本或整个产品生命周期的构建总数.

Then the Build is used separately to indicate the total number of builds for a release or for the entire product lifetime.

许多开发人员从 0 开始构建编号,并且每次构建时都会将编号增加 1,并永远增加.在我的项目中,我有一个脚本,每次构建时都会自动增加构建号.请参阅下面的说明.

Many developers start the Build number at 0, and every time they build they increase the number by one, increasing forever. In my projects, I have a script that automatically increases the build number every time I build. See instructions for that below.

  • 版本 1.0.0 可能是 build 542.需要 542 个 build 才能达到1.0.0 版本.
  • 1.0.1 版可能是 build 578.
  • 1.1.0 版可能是 build 694.
  • 2.0.0 版可能是 build 949.

包括 Apple 在内的其他开发者的内部版本号由主要版本 + 次要版本 + 版本的内部版本号组成.这些是实际的软件版本号,而不是用于营销的值.

Other developers, including Apple, have a Build number comprised of a major version + minor version + number of builds for the release. These are the actual software version numbers, as opposed to the values used for marketing.

如果您转到 Xcode 菜单 > 关于 Xcode,您将看到版本号和内部版本号.如果您点击更多信息... 按钮,您会看到许多不同的版本.由于 更多信息... 按钮已在 Xcode 5 中删除,因此也可以从 系统信息软件 > 开发人员 部分获得此信息应用程序,可通过打开 Apple 菜单 > 关于本机 > 系统报告...获得.

If you go to Xcode menu > About Xcode, you'll see the Version and Build numbers. If you hit the More Info... button you'll see a bunch of different versions. Since the More Info... button was removed in Xcode 5, this information is also available from the Software > Developer section of the System Information app, available by opening Apple menu > About This Mac > System Report....

例如,Xcode 4.2 (4C139).营销版本 4.2 是 Build 主要版本 4、Build 次要版本 C 和 Build 号 139.下一个版本(大概是 4.3)可能是 Build 版本 4D,并且 Build 号将从 0 开始并从那里开始递增.

For example, Xcode 4.2 (4C139). Marketing version 4.2 is Build major version 4, Build minor version C, and Build number 139. The next release (presumably 4.3) will likely be Build release 4D, and the Build number will start over at 0 and increment from there.

iPhone 模拟器版本/内部版本号与 iPhone、Mac 等相同.

The iPhone Simulator Version/Build numbers are the same way, as are iPhones, Macs, etc.

  • 3.2:(7W367a)
  • 4.0:(8A400)
  • 4.1:(8B117)
  • 4.2: (8C134)
  • 4.3: (8H7)

更新:根据请求,以下是创建脚本的步骤,该脚本每次在 Xcode 中构建应用程序时都会运行,以读取构建号、递增它并将其写回应用程序的 <代码>{App}-Info.plist 文件.如果您想将版本/内部版本号写入 Settings.bundle/Root*.plist 文件,还有一些可选的附加步骤.

Update: By request, here are the steps to create a script that runs each time you build your app in Xcode to read the Build number, increment it, and write it back to the app's {App}-Info.plist file. There are optional, additional steps if you want to write your version/build numbers to your Settings.bundle/Root*.plist file(s).

这是从操作方法文章此处扩展而来.

在 Xcode 4.2 - 5.0 中:

In Xcode 4.2 - 5.0:

  1. 加载您的 Xcode 项目.
  2. 在左侧窗格中,单击层次结构最顶部的项目.这将加载项目设置编辑器.
  3. 在中央窗口窗格的左侧,点击目标标题下的应用.您需要为每个项目目标配置此设置.
  4. 选择构建阶段标签.
    • 在 Xcode 4 中,点击右下角的添加构建阶段按钮并选择添加运行脚本.
    • 在 Xcode 5 中,选择 Editor 菜单 > 添加构建阶段 > 添加运行脚本构建阶段.
  1. Load your Xcode project.
  2. In the left hand pane, click on your project at the very top of the hierarchy. This will load the project settings editor.
  3. On the left-hand side of the center window pane, click on your app under the TARGETS heading. You will need to configure this setup for each project target.
  4. Select the Build Phases tab.
    • In Xcode 4, at the bottom right, click the Add Build Phase button and select Add Run Script.
    • In Xcode 5, select Editor menu > Add Build Phase > Add Run Script Build Phase.

将以下内容复制并粘贴到整数内部版本号的脚本区域:

Copy and paste the following into the script area for integer build numbers:

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

正如@Bdebeez 指出的那样,Apple 通用版本控制工具 (agvtool) 也可用.如果您更喜欢使用它,那么首先需要更改以下几点:

As @Bdebeez pointed out, the Apple Generic Versioning Tool (agvtool) is also available. If you prefer to use it instead, then there are a couple things to change first:

  • 选择构建设置标签.
  • 版本控制部分下,将当前项目版本设置为您要使用的初始版本号,例如1.莉>
  • 返回构建阶段标签,在复制捆绑资源阶段后拖放您的运行脚本阶段以避免竞争尝试构建和更新包含您的构建号的源文件时的条件.
  • Select the Build Settings tab.
  • Under the Versioning section, set the Current Project Version to the initial build number you want to use, e.g., 1.
  • Back on the Build Phases tab, drag-and-drop your Run Script phase after the Copy Bundle Resources phase to avoid a race condition when trying to both build and update the source file that includes your build number.

请注意,使用 agvtool 方法,您可能仍会定期获得失败/取消的构建,没有错误.因此,我不建议在此脚本中使用 agvtool.

Note that with the agvtool method you may still periodically get failed/canceled builds with no errors. For this reason, I don't recommend using agvtool with this script.

尽管如此,在您的运行脚本阶段,您可以使用以下脚本:

Nevertheless, in your Run Script phase, you can use the following script:

"${DEVELOPER_BIN_DIR}/agvtool" next-version -all

next-version 参数增加内部版本号(bump 也是同一事物的别名),-all 更新 Info.plist 带有新的内部版本号.

The next-version argument increments the build number (bump is also an alias for the same thing), and -all updates Info.plist with the new build number.

如果您有一个显示版本和构建的设置包,您可以将以下内容添加到脚本的末尾以更新版本和构建.注意:更改 PreferenceSpecifiers 值以匹配您的设置.PreferenceSpecifiers:2 表示查看 plist 文件中 PreferenceSpecifiers 数组下索引 2 处的项目,因此对于基于 0 的索引,这是数组中的第三个首选项设置.

And if you have a Settings bundle where you show the Version and Build, you can add the following to the end of the script to update the version and build. Note: Change the PreferenceSpecifiers values to match your settings. PreferenceSpecifiers:2 means look at the item at index 2 under the PreferenceSpecifiers array in your plist file, so for a 0-based index, that's the 3rd preference setting in the array.

productVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root.plist
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root.plist

如果您使用 agvtool 而不是直接阅读 Info.plist,您可以将以下内容添加到您的脚本中:

If you're using agvtool instead of reading the Info.plist directly, you can add the following to your script instead:

buildNumber=$("${DEVELOPER_BIN_DIR}/agvtool" what-version -terse)
productVersion=$("${DEVELOPER_BIN_DIR}/agvtool" what-marketing-version -terse1)
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root.plist
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root.plist

  • 如果您有适用于 iPad 的通用应用程序iPhone,然后您还可以设置iPhone文件的设置:

  • And if you have a universal app for iPad & iPhone, then you can also set the settings for the iPhone file:

    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root~iphone.plist    
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root~iphone.plist
    

  • 这篇关于版本与在 Xcode 中构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆