Search code examples
macosxcodebuild

xcodebuild - how to specify the directory where the project is, without doing a cd in it


I am using xcodebuild from command line in a script, but I realized that I cannot specify the path of the project that i wanna build;I am forced to cd in the folder where the project is.

Is there a way to accomplish the build process without having to cd in the directory, or this is how it must be?

Is not a big deal to cd into the directory and execute xcodebuild, but I wonder what if someday you need to build a project and you cannot cd into the directory....It doesn't really make sense to me to not being able to specify the path.


Solution

  • You must be in the directory containing the project(s) when you run xcodebuild. If you don’t want to mess with your current directory, there a couple of options:

    /bin/sh -c "cd $PRJDIR; xcodebuild"
    

    or

    (cd $PRJDIR; xcodebuild)