I have found a solution. I am changing application icons in the .xcasset source folder and not in Derived Data (using ImageMagick). So here is my script:
#!/bin/bash IFS=$'\n' BASE_ICONS_DIR=$(find ${SRCROOT}/${PRODUCT_NAME} -name "AppIcon.appiconset") IFS=$' ' CONTENTS_JSON="${BASE_ICONS_DIR}/Contents.json" version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFOPLIST_FILE}"`
This script runs before Copy Bundle Resources . After the application icons are changed, I need to revert the changes using an additional script run as the last build phase:
if [ "${CONFIGURATION}" != "AppStore" ]; then IFS=$'\n' git checkout -- `find "${SRCROOT}/${PRODUCT_NAME}" -name AppIcon.appiconset -type d` fi
My build phases are as follows:

source share