如果选择了调试配置,则将文件复制到App Resources目录 [英] Copy file to the App Resources directory if debug configuration is selected

查看:85
本文介绍了如果选择了调试配置,则将文件复制到App Resources目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在调试版本中将一些文件复制到App的Resources目录中。我正在考虑使用构建规则,但不知道如何确定构建是否是调试版本。我有一个DEBUG设置的编译器选项。

I need to copy a few files into the App's Resources directory during debug builds. I am thinking about using build rules but don't know how to determine if the build is a debug build. I do have a compiler option of "DEBUG" set.

推荐答案

您可以使用运行脚本构建阶段进行复制。构建目标时应用的所有构建设置都可以通过脚本中的环境变量获得。

You can use a Run Script build phase to do the copying. All build settings applied when building the target are available via environment variables in your script.

您可以通过 CONFIGURATION <确定正在构建的配置/ code>环境变量;您可以查看其他环境变量,例如 BUILT_PRODUCTS_DIR ,以确定放置资源的位置。如果正确指定了运行脚本构建阶段的输出,则只有在需要更新输出时才会运行它,而不是每次构建时都会运行。

You can determine what configuration is being built via the CONFIGURATION environment variable; you can look at other environment variables like BUILT_PRODUCTS_DIR to determine where to put your resource. If you specify your Run Script build phase's output correctly, it will only be run when the output needs to be brought up to date, not every time you build.

更多信息有关运行脚本构建阶段的信息,请访问: Xcode Build System Guide:Build阶段:Run Script Build Phase

More information on Run Script build phases is available here: Xcode Build System Guide: Build Phases: Run Script Build Phase

使用脚本构建规则可以完成同样的事情,如果您要将多个资源应用于此目的,这将非常有用:您可以创建与您的扩展名匹配的脚本构建规则(例如 *。 myresource )并使用通过环境变量传递给脚本的构建设置和输入文件来进行实际复制。如果正确指定构建规则的输出,则仅在其输入比其输出更新时运行,而不是每次构建时都运行。

The same kind of thing can be done with script build rules, which is useful if you have multiple resources you want to apply this to: You can create a script build rule that matches your extension (e.g. *.myresource) and use the build settings and input files that are passed to your script via environment variables to do the actual copying. If you specify your build rule's output correctly, it will only be run when its input is newer than its output, not every time you build.

有关脚本构建规则的更多信息可在此处获取: Xcode构建系统指南:构建阶段:构建规则

More information on script build rules is available here: Xcode Build System Guide: Build Phases: Build Rules

这篇关于如果选择了调试配置,则将文件复制到App Resources目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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