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

查看:82
本文介绍了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) )和捆绑版本作为您的构建(例如,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 (Build)。

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} 。{修订版}

{MajorVersion}.{MinorVersion}.{Revision}


  • 主要版本 - 重大更改,重新设计和功能
    更改

  • 次要版本 - 次要改进,功能增加

  • 修订版 - 错误的修补程序编号-fixes

  • Major version - Major changes, redesigns, and functionality changes
  • Minor version - Minor improvements, additions to functionality
  • Revision - A patch number for bug-fixes

然后单独使用Build来指示构建的总数f或者发布或整个产品生命周期。

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可能是构建542.它花了542个版本来获得
    1.0 .0 release。

  • 版本1.0.1可能是构建578。

  • 版本1.1.0可能是构建版本694。

  • 版本2.0.0可能是构建949。

  • Release 1.0.0 might be build 542. It took 542 builds to get to a 1.0.0 release.
  • Release 1.0.1 might be build 578.
  • Release 1.1.0 might be build 694.
  • Release 2.0.0 might be 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是构建主要版本4,构建次要版本C和构建号码139.下一个版本(可能是4.3)可能是构建版本4D,并且构建号码将从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)

  • 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. 在中心窗格的左侧,单击 TARGETS 标题下的应用程序。您需要为每个项目目标配置此设置。

  4. 选择构建阶段选项卡。


    • 在Xcode 4的右下角,点击添加构建阶段按钮,然后选择添加运行脚本

    • 在Xcode 5中,选择编辑菜单> 添加构建阶段> 添加运行脚本构建阶段

  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 Generic Versioning Tool 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:


  • 选择构建设置 tab。

  • 版本控制部分下,将当前项目版本设置为您要使用的初始版本号,例如, 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和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天全站免登陆