Reputation: 40257
I wonder if there is any way to run scripts before build starts in Xcode. There is way from
Build phase -> Run scripts
But this runs after the actual build is finished. I need to run script before Xcode build starts though.
Upvotes: 5
Views: 11542
Reputation: 632
Niether of the above variants helped me. For archive command they are usually lately executed and do not update the version for me. Found another possibility to run script and update version definitely before the build process starts.
Edit scheme...
Build
section in left menu and select Pre-actions
item+
at the bottom left of the main window and then select New Run Script Action
That's all. This script will be executed every time right before build is started.
Upvotes: 2
Reputation: 122458
The best approach is to create pseudo target in your project.
For example, say you have a shell script that sets the app version by updating an .xcconfig
file:
SetAppVersion
of type Other
> External Build System
./bin/bash
, set the Arguments to whatever script does the work, for example scripts/set_app_version.sh
and set the Directory to $(PROJECT_DIR)
.Now for any target affected by this script, simply make the SetAppVersion
target a dependency of it, and it will run before any other action is performed on those targets.
Upvotes: 1
Reputation:
You need to add a build phase. Go to the project file, Build Phases, click Editor on the tool bar menu, add Build Phase, Add Run Script... You can select and drag the script to put it before/after anything.
Upvotes: 9
Reputation: 287
If you want to change the code or assets via the script before they get compiled, just move the Run Script phase above the Compile Sources phase.
Upvotes: 4