How to have Xcode always copy files (even if they have not been detected as modified) when building?

12,178

Solution 1

You could right- or control-click the file (in the project file list) and click "Touch" before building (manual) or add a script build phase to the target that calls "touch myfile.js" and place it before your Copy Files build phase (automatic).

Solution 2

Add a new Copy Files Build Task to your target.

Right Click (Control Click) on the target, Add -> New Build Phase -> New Copy Files Build Phase.

In the Dialog select the destination that you want the files to be copied.

This will create the phase under the target. Drag the files you wish to copy to the phase.

Share:
12,178
Form
Author by

Form

Software developer to the core. Probably coding at this very moment.

Updated on June 24, 2022

Comments

  • Form
    Form almost 2 years

    I am developing an application which uses .js files stored in the Resources/javascript folder of my application bundle. In my Xcode 2.5 project I have created a folder reference (not a group) to my javascript folder, which automatically added the folder to the Copy Bundle Resources build phase.

    The problem I have is when I modify my .js files, I need to clean my project then re-build it for the modified .js files to get copied into my application bundle when building. This is very time consuming since I re-build the whole project just to get an updated .js file in my app bundle.

    Could someone tell me how to get Xcode to always copy specific files in the build phase?

    Thanks in advance!

  • Form
    Form over 14 years
    I tried that but the files weren't copied... maybe it only works with source code files?
  • Form
    Form over 14 years
    This does the same thing as the Copy Bundle Resources build phase: it does not copy the files each time.
  • Joshua Nozzi
    Joshua Nozzi over 14 years
    Almost seems like something else is going on. It's weird enough that modifying the file isn't enough to get it copied, but directly telling it to touch the file first, then going about the copy files build phase should definitely get it going if it's set up right. More detail would be helpful.
  • Elise van Looij
    Elise van Looij over 14 years
    I have recreated what you described, namely creating a link to a folder (outside the project) containing javascript files. I then added the Copy File Build Phase, selected Resources from the select box, added 'javascript' as the path, added all the javascript files to it and ran and build the app. All the files were copied into the bundle at Contents/Resources/javascript. I then made a minor change to one of the javascript files, build the app again, and the change showed up as expected. This was, however, in Debug build configuration. Perhaps you are using something else?
  • Form
    Form over 14 years
    Maybe it has something to do with the folder reference? It's not actually a group in the Xcode sidebar. I can't think of anything different other than that...
  • Form
    Form over 14 years
    Nope, I am not using another build config. Note that I'm working in Xcode 2.5 on Tiger though as I stated in my question. Maybe it doesn't work that way in 2.5?
  • Elise van Looij
    Elise van Looij over 14 years
    Must be. 2.5, eh? Well, I'm sure there are good reasons for sticking to 2.5 ... no, there aren't. Save yourself, upgrade.
  • Joshua Nozzi
    Joshua Nozzi over 14 years
    If Xcode behaves this way each time and is reproducible, I'd definitely call this a bug. bugreporter.apple.com
  • mpontillo
    mpontillo almost 11 years
    +1; I did something similar. Add a "runs script" step before the "copy files" step which calls find ../path/to/files | xargs touch. This solved the problem for me. Thanks!