Trying to solve this problem last night, I came across this great script to automate the process. Works great, right out of the box.
If you want to integrate this with an xcodebuild, you’ll still need to build a small xcodeproj file. There’s a template for this and instructions here: