Xcode - 如何在构建后将可执行文件复制到新位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13509095/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:09:54  来源:igfitidea点击:

Xcode - How to copy executable to new location after build?

xcodexcode4

提问by tarmes

I'm building a command line application using Xcode 4.

我正在使用 Xcode 4 构建命令行应用程序。

Once the build is complete the executable is located inside the default DerivedData folder. This is OK, however I'd then like to copy this file to a specific folder. I'd like this to happen regardless of the type of build (release/debug).

构建完成后,可执行文件位于默认的 DerivedData 文件夹中。没关系,但是我想将此文件复制到特定文件夹。无论构建类型(发布/调试)如何,我都希望这种情况发生。

Can anyone please suggest a way of doing this?

任何人都可以请建议这样做的方法吗?

As an aside, the subdirectory for my project inside DerivedData has a tag of random characters in it:

顺便说一句,我的项目在 DerivedData 中的子目录中有一个随机字符的标签:

myProject-fnkwvtitgroivocadokaayqexhqy

Does anyone know if this can change over time (thus changing the location of my executable to be copied), or is it fixed for this project?

有谁知道这是否会随着时间的推移而改变(从而改变我要复制的可执行文件的位置),或者它是否适用于这个项目?

回答by GW.Rodriguez

There's actually a great way to automate this. Assuming you're in your Xcode project currently, click on the project file and click on the target (since you said that it's a simple command-line program, there should only be one).

实际上有一个很好的方法来自动化这个。假设您当前在 Xcode 项目中,单击项目文件并单击目标(​​因为您说它是一个简单的命令行程序,因此应该只有一个)。

Next click on the tab Build Phases and open the triangle for Copy Files.

接下来单击选项卡构建阶段并打开复制文件的三角形。

(If you don't see a triangle with "Copy Files", click on the + symbol to add it.)

(如果您没有看到带有“复制文件”的三角形,请单击 + 符号进行添加。)

Now in the navigator in the Products folder will be the executable that is built. Drag this into the Copy Files build phase.

现在在 Products 文件夹的导航器中将是构建的可执行文件。将其拖入复制文件构建阶段。

In the Copy Files little menu click on the drop menu to choose Absolute Path and below that type in the path where you'd like it to be installed. Make sure to check "Copy only when installing" and every time you build the project and it succeeds it will copy the executable to that location.

在“复制文件”小菜单中,单击下拉菜单以选择“绝对路径”,然后在该路径下方键入您希望安装它的路径。确保选中“仅在安装时复制”,每次构建项目并成功时,它都会将可执行文件复制到该位置。

回答by Scott Combs

In my case, I wanted the newly built app to be copied over existing builds in the Application's folder. In the Build Rules, add a New Run Script Phaseto the list. I use /bin/bash, but you can probably use the default /bin/shtoo. Then, I added the following code to the script.

就我而言,我希望将新建的应用程序复制到应用程序文件夹中的现有版本上。在构建规则中,将 a 添加New Run Script Phase到列表中。我使用/bin/bash,但您也可以使用默认值/bin/sh。然后,我将以下代码添加到脚本中。

cp -f -R ${BUILT_PRODUCTS_DIR}/${APPLICATION_NAME} /Applications