Search code examples
xcodexcodebuild

How do I force Xcode to rebuild the Info.plist file in my project every time I build the project?


Apparently the file gets cached, so it only gets built when it gets changed. I have environment variables set to increment my version number though, and such, and update them independently of the plist (in the project build settings, actually). Is there a script that I can use as a script build phase that will force the Info.plist to update? Some other convenient way?


Solution

  • Select 'Edit Scheme', then select 'Build' from the control on the left.

    Then, add a Pre-actions step, ensure the scheme in question is selected in the 'Provide build settings from' pulldown and then add this into the edit window below:

    rm "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"
    

    This will delete the cached version of Info.plist, causing XCode to rebuild it each time you hit build.

    Alternatively, if you let Xcode preprocess a template Info.plist file, simply touching the template with

    touch ${PROJECT_DIR}/${INFOPLIST_FILE}
    

    works too.

    Debugging pre-action scripts

    The pre-actions steps do not provide any information when you have made a mistake. You can debug the use of your build variables by adding this line to the script

    echo "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}" > ~/debug.txt
    

    Then check the content of ~/debug.txt to verify that the pre-action script has run and to see if you've used the correct path.