Xcode:项目设置与目标设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1642710/
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 settings vs. target settings
提问by vectorizor
I'm creating a static lib on Mac OS X for one of our customers, as well as a small cmd line app to test the static lib. The cmd line project has 2 extra library search paths, which meant I was linking to the Debug version in Release mode and just about went crazy, so I tried to get rid of these two paths, but I couldn't find where they were specified. I was looking in the project info, but it turns out they were specified in the target info.
我正在为我们的一位客户在 Mac OS X 上创建一个静态库,以及一个用于测试静态库的小型 cmd 行应用程序。cmd line 项目有 2 个额外的库搜索路径,这意味着我在 Release 模式下链接到 Debug 版本并且几乎疯了,所以我试图摆脱这两个路径,但我找不到它们被指定的位置. 我正在查看项目信息,但结果发现它们是在目标信息中指定的。
I don't understand the distinction?! Why there are 2 sets of settings, which are essentially the same?! Can someone please enlighten me?
没看懂区别?!为什么会有2套设置,本质上是一样的?!有人可以启发我吗?
回答by iKenndac
A project can contain multiple targets. For example, an app I write has four - the app itself, a Quick Look plugin, a framework and a bundle that contains Mac OS 10.6-specific functionality that can be dynamically loaded in.
一个项目可以包含多个目标。例如,我编写的一个应用程序有四个——应用程序本身、一个快速查看插件、一个框架和一个包,其中包含可以动态加载的 Mac OS 10.6 特定功能。
Project settings apply to every single target in the project. Each target can then override individual settings if they need to - for instance, my project's Target SDK is set to 10.5, but the 10.6-specific bundle has it's Target SDK set to 10.6.
项目设置适用于项目中的每个目标。如果需要,每个目标然后可以覆盖单独的设置 - 例如,我的项目的目标 SDK 设置为 10.5,但 10.6 特定的包将它的目标 SDK 设置为 10.6。
In some instances, some settings don't make sense to be in Project Settings - one of these, I guess, is search paths.
在某些情况下,某些设置在项目设置中没有意义 - 我猜其中之一是搜索路径。
回答by Jonathan del Strother
You often have multiple targets in a single project - for instance, you might have a framework project with a target for building as a dynamic .framework bundle, and a target for building a static lib. Or your app might have a target for building the app itself, and a target for building some helper command-line tool that it needs to install.
您通常在一个项目中有多个目标 - 例如,您可能有一个框架项目,其目标是构建为动态 .framework 包,目标是构建静态库。或者您的应用程序可能有一个用于构建应用程序本身的目标,以及一个用于构建它需要安装的帮助命令行工具的目标。
Wherever possible, I'd suggest changing settings at the highest level (in the project settings, and simultaneously changing debug & release configurations), and only customizing the target settings when necessary. Even better, move as many settings as possible into xcconfig files, which seem a much more explicit way of specifying your build setup.
在可能的情况下,我建议更改最高级别的设置(在项目设置中,同时更改调试和发布配置),并且仅在必要时自定义目标设置。更好的是,将尽可能多的设置移动到 xcconfig 文件中,这似乎是一种更明确的指定构建设置的方式。
回答by Honey
Preface: you ship targets. Your end products are targets. Not projects. Think of a project as the umbrella above multiple targets.
前言:你运送目标。您的最终产品是目标。不是项目。将项目视为多个目标之上的保护伞。
For a more realistic example assume both Uber and Lyft were being developed by the your (umbrella) company.
举一个更现实的例子,假设优步和 Lyft 都是由你的(伞)公司开发的。
The company has the following three environments:
公司有以下三种环境:
- Debug
- QA
- Release
- 调试
- 质量保证
- 释放
The Debug and Release configs come out of the box with every new project you create. You can create as many additional configs as you want
调试和发布配置随您创建的每个新项目开箱即用。您可以根据需要创建任意数量的附加配置
This would require 3 configurations. To add a QA configuration follow the tutorial here
这将需要 3 个配置。要添加 QA 配置,请按照此处的教程进行操作
Did I apply this to the target or project?
我是否将其应用于目标或项目?
I applied it to the project.
我把它应用到项目中。
Ok so configs are only for projects and not for targets. Right?
好的,所以配置仅适用于项目而不适用于目标。对?
Incorrect! It's confusing I know. You have to think of the project as a big container where you create your configs in there.
不正确!我知道这很混乱。您必须将项目视为一个大容器,您可以在其中创建配置。
Then for each target (not project), for following tabs:
然后对于每个目标(不是项目),对于以下选项卡:
General, Resource Tags, Build Phases, Build rules, Info:
常规、资源标签、构建阶段、构建规则、信息:
There is no difference between different configs
不同的配置没有区别
Signing and Capabilities tab:
签名和功能选项卡:
You can switch between teams and sign it with a different team. This is useful if you want to sign your beta builds with your enterprise certificate but sign your Appstore build with app store certificate.
您可以在团队之间切换并与不同的团队签约。如果您想使用您的企业证书签署您的 Beta 版本,但使用应用商店证书签署您的 Appstore 构建,这将非常有用。
Build Settings tab:
构建设置选项卡:
For almost every variable in this section you can give a different value based on the config. Common Build Settings to customize are:
对于本节中的几乎每个变量,您都可以根据配置给出不同的值。要自定义的常见构建设置是:
- Architectures - 'Build Active Architecture only'
- Build Options 'Debug Information Format'
- Packaging
- Set the plist you want per configuration.
- Change the bundle identifier (Packaging >> Product Bundle Identifier). If you switch values for a field then in the plist you'll see as:
- Signing
- Code Signing identity
- Code Signing Style (Manual or Automatic)
- Development team
- Provisioning Profile
- Apple Clang - Optimization Level
- 架构 - '仅构建活动架构'
- 构建选项“调试信息格式”
- 包装
- 根据配置设置所需的 plist。
- 更改捆绑标识符(Packaging >> Product Bundle Identifier)。如果您为字段切换值,则在 plist 中您将看到:
- 签约
- 代码签名身份
- 代码签名样式(手动或自动)
- 开发小组
- 配置文件
- Apple Clang - 优化级别
If the values are different then the row's value would be
如果值不同,则该行的值将是
<Multiple values>
and you basically have to expand that value to see what value is given for debug and what value is given for Release or QA config.
并且您基本上必须扩展该值以查看为调试提供的值以及为发布或 QA 配置提供的值。
If all the values are the same then you'll just see the value that is given to all of them. By default the values are the same.
如果所有值都相同,那么您只会看到赋予所有值的值。默认情况下,这些值是相同的。
Long story short, this allows you to have 2 different apps (targets) with the same code (project), in 3 different environments (dev, QA, release). You create the different environments using configurations.
长话短说,这允许您在 3 个不同的环境(开发、QA、发布)中拥有 2 个具有相同代码(项目)的不同应用程序(目标)。您可以使用配置创建不同的环境。
To learn more on this I highly recommend you to read more about this in depth and understand what configuration files (xcconfig) is. It's much more simpler than you think. It's mainly a key value pair:
要了解更多信息,我强烈建议您深入阅读更多相关信息,并了解什么是配置文件 (xcconfig)。它比你想象的要简单得多。主要是一个键值对: