如何保存 1 个 xcode 项目中的所有构建设置并在其他 xcode 项目中使用它们?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14484338/
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
How can I save all my build settings from 1 xcode project and use them on other xcode projects?
提问by Rob Elder
I'm using xcode 4.5 and cordova/phonegap to build my apps. I have invested a lot of time into getting the build settings just right for my xcode project and I would like to reuse these settings on multiple apps I am building. I'm looking to see if there is a fast way to export these settings or build a template that I can use for future projects.
我正在使用 xcode 4.5 和 cordova/phonegap 来构建我的应用程序。我花了很多时间来为我的 xcode 项目设置合适的构建设置,我想在我正在构建的多个应用程序上重用这些设置。我想看看是否有一种快速的方法可以导出这些设置或构建可用于未来项目的模板。
I've tried copying the project folder and changing the name and that does not work. I get an error when working with the cordovalib.xcodeproj file.
我试过复制项目文件夹并更改名称,但不起作用。使用cordovalib.xcodeproj 文件时出现错误。
Any help on exporting these settings or creating a template would be appreciated.
任何有关导出这些设置或创建模板的帮助将不胜感激。
回答by StuR
Use an .xcconfig file.
使用 .xcconfig 文件。
File.. New File.. Then choose the Configuration Settings File from the Other section.
文件.. 新建文件.. 然后从其他部分选择配置设置文件。
You will have to copy the build settings from your xcodeproj file. Open your xcodeproj file in a text editor and copy:
您必须从 xcodeproj 文件中复制构建设置。在文本编辑器中打开您的 xcodeproj 文件并复制:
buildSettings = { ... }
Into your xcconfig file. Be aware that the xcconfig file has a specific format. The above video / Apple documentation should help you.
进入你的 xcconfig 文件。请注意,xcconfig 文件具有特定格式。上面的视频/Apple 文档应该对您有所帮助。
You will then need to tell Xcode which xcconfig file to use for each build configuration.. Debug, Release, etc. You can do this by importing it under your Project's Info tab, under Configurations.
然后你需要告诉 Xcode 哪个 xcconfig 文件用于每个构建配置......调试、发布等。你可以通过在你的项目的信息选项卡下的配置下导入它来做到这一点。
回答by CoFa1
XCConfig files are certainly the way to go for sharing build settings across multiple targets or even projects.
XCConfig 文件当然是跨多个目标甚至项目共享构建设置的方式。
As StuR wrote six years ago, you still add a configuration file from the New File dialog in XCode. It is just a text file with a key value format. The easiest way to add configuration values is —?in my opinion —?to go to the build settings of your target, select the row of the setting you want to modify and press cmd+c to copy it. When you paste in the config file, it will be inserted in the right format.
正如 StuR 六年前所写,您仍然可以从 XCode 的“新建文件”对话框中添加配置文件。它只是一个具有键值格式的文本文件。添加配置值的最简单方法是——?在我看来——?转到目标的构建设置,选择要修改的设置行,然后按 cmd+c 复制它。当您粘贴配置文件时,它将以正确的格式插入。
To add the config file to your target, you need to go to the project settings. There is a Configurations section where you can set the config files for each target and configuration (Debug, Release, etc)
要将配置文件添加到您的目标,您需要转到项目设置。有一个配置部分,您可以在其中为每个目标和配置(调试、发布等)设置配置文件
You find the official documentation for XCConfig files here: https://help.apple.com/xcode/mac/10.1/#/dev745c5c974
您可以在此处找到 XCConfig 文件的官方文档:https://help.apple.com/xcode/mac/10.1/#/dev745c5c974
One very usefull feature of the XCConfig files is that you can import other XCConfig files and build a kind of inheritance schema.
XCConfig 文件的一个非常有用的功能是您可以导入其他 XCConfig 文件并构建一种继承模式。