title: Continuous Integration Code Signing issue
body: <p>I've been working on setting up a TeamCity continuous integration build agent for my iOS builds and I've run into a bit of a road block.</p>
  
  <p>We're going to be making builds for different clients with different certificates and mobile provisioning profiles, so I figured I would write a build script that would create an unsigned archive, then sign it with the appropriate identity and mobileprovision.  It seems like the xcrun command doesn't like that the .app file is not signed, and therefore won't sign it.</p>
  
  <p>Am I doing something wrong, or is there some other, more elegant way of accomplishing what I'm trying to do?</p>
  
  <p><em>Infodump follows...</em></p>
  
  <hr>
  
  <p>I'm creating the unsigned build with the following command:</p>
  
  <pre><code>xcodebuild -workspace "[workspace].xcworkspace" -scheme "[scheme]" clean archive CODE_SIGN_ENTITY="" CODE_SIGNING_REQUIRED=NO
  </code></pre>
  
  <p>Then, I'm attempting to code sign and create the IPA with this command:</p>
  
  <pre><code>APP=[path to .app file in archive]
  OUT_IPA=[desired location of .ipa]
  IDENTITY=[CodeSigning Identity]
  MOBILE_PROVISION=[path to .mobileprovision]
  xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "${OUT_IPA}" --sign "${IDENTITY}" --embed "${MOBILE_PROVISION}"
  </code></pre>
  
  <p>The xcrun command prints a bunch of debug info, then copies files around to temporary directories.  Then it checks the original app</p>
  
  <pre><code>### Checking original app
  
  + /usr/bin/codesign --verify -vvvv /Users/jibanez/Library/Developer/Xcode/Archives/2012-09-14/[scheme] 9-14-12 12.02 PM.xcarchive/Products/Applications/[product].app
  Program /usr/bin/codesign returned 1 : [/Users/jibanez/Library/Developer/Xcode/Archives/2012-09-14/[scheme] 9-14-12 12.02 PM.xcarchive/Products/Applications/[product].app: code object is not signed at all
  In architecture: armv7
  ]
  Codesign check fails : /Users/jibanez/Library/Developer/Xcode/Archives/2012-09-14/[scheme] 9-14-12 12.02 PM.xcarchive/Products/Applications/[product].app: code object is not signed at all
  In architecture: armv7
  
  Done checking the original app
  </code></pre>
  
  <p>This seems about right.  After all, I didn't code sign the archive, that's what xcrun is supposed to do.  Here's where things get weird:</p>
  
  <pre><code>### Embedding '/Users/jibanez/Documents/[projectdir]/codesign/[scheme]/842F2922-D0CB-46CE-81E5-B7362DD1D960.mobileprovision'
  + /bin/rm -rf /var/folders/hh/qhf8930s5hg8lwbp2j_zsdm822y1s1/T/NycIiYdEYe/Payload/[product].app/embedded.mobileprovision
  Program /bin/rm returned 0 : []
  + /bin/cp -rp /Users/jibanez/Documents/[projectdir]/codesign/[scheme]/mobileProvision.mobileprovision /var/folders/hh/qhf8930s5hg8lwbp2j_zsdm822y1s1/T/NycIiYdEYe/Payload/[product].app/embedded.mobileprovision
  Program /bin/cp returned 0 : []
  + /usr/bin/codesign -d --entitlements /var/folders/hh/qhf8930s5hg8lwbp2j_zsdm822y1s1/T/NycIiYdEYe/entitlements_rawwAdCadPV /var/folders/hh/qhf8930s5hg8lwbp2j_zsdm822y1s1/T/NycIiYdEYe/Payload/[product].app
  Program /usr/bin/codesign returned 1 : [/var/folders/hh/qhf8930s5hg8lwbp2j_zsdm822y1s1/T/NycIiYdEYe/Payload/[product].app: code object is not signed at all
  ]
  error: Failed to read entitlements from '/var/folders/hh/qhf8930s5hg8lwbp2j_zsdm822y1s1/T/NycIiYdEYe/Payload/[product].app'
  Failed: PackageApplication
  </code></pre>