fuzzygoat
fuzzygoat

Reputation: 26223

How to clean project before each build?

Is there a way (possibly using schemes) in Xcode to specify that a clean is automatically done before doing a new build.?

I have a project that sometimes fails to build unless I do a clean first, currently I am doing it by hand.

Upvotes: 10

Views: 5387

Answers (2)

keisar
keisar

Reputation: 5326

The selected answer did not work for me, it caused my build to fail (Xcode 4.6.3) when trying to run on the simulator.
Based on Jano's answer and on this link in the Pre-action script instead of writing

rm -rf ${BUILT_PRODUCTS_DIR}  

I wrote

touch ${BUILT_PRODUCTS_DIR}

This should have the same effect and it doesn't cause my build to fail

Upvotes: 4

Jano
Jano

Reputation: 63667

Press ⌥⌘R, expand the selected scheme, select Pre-actions, click +, select New Run Script Action, set Provide Build Settings from to your target. In the box below type rm -rf ${BUILT_PRODUCTS_DIR}. Note: it is BUILT not BUILD as seen in the Xcode dialog. You can type echo ${BUILT_PRODUCTS_DIR} > ~/Desktop/log.txt to see what's going to be deleted.

Upvotes: 27

Related Questions