title: Codesign returns unknown error after "replacing existing signature"
body: <p>I am trying to build a Xamarin iOS app using xbuild on Jenkins. Sometimes the build fails during the codesigning process with an <em>unknown error -1=ffffffffffffffff</em> and sometimes the build succeeds. The provisioning profile is stored in a separate keychain <em>jenkins.keychain</em> (not the system or login keychain) that is referenced by Jenkins through the <a href="https://wiki.jenkins.io/display/JENKINS/Keychains+and+Provisioning+Profiles+Plugin" rel="nofollow noreferrer">Keychains and Provisioning Profiles Plugin</a>.</p>
  
  <p>This is the console log of Jenkins:</p>
  
  <pre><code>Target _CodesignAppBundle:
      Codesign Task
        CodesignAllocate: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
        DisableTimestamp: False
        Entitlements: obj/iPhone/In-House/Entitlements.xcent
        Keychain: &lt;null&gt;
        Resources:
          bin/iPhone/In-House/MyApp.app
        ResourceRules: &lt;null&gt;
        SigningKey: 123
        ExtraArgs: &lt;null&gt;
        IsAppExtension: False
      Tool /usr/bin/codesign execution started with arguments: -v --force --sign 123 --entitlements /private/var/lib/jenkins/workspace/Master/Apps/iOS/obj/iPhone/In-House/Entitlements.xcent /private/var/lib/jenkins/workspace/Master/Apps/iOS/bin/iPhone/In-House/MyApp.app
  
  
  bin/iPhone/In-House/MyApp.app: error : /private/var/lib/jenkins/workspace/Master/Apps/iOS/bin/iPhone/In-House/MyApp.app: replacing existing signature
     /private/var/lib/jenkins/workspace/Master/Apps/iOS/bin/iPhone/In-House/MyApp.app: unknown error -1=ffffffffffffffff
      Task "Codesign" execution -- FAILED
      Done building target "_CodesignAppBundle" in project "/private/var/lib/jenkins/workspace/Master/Apps/iOS/MyApp.csproj".-- FAILED
  </code></pre>
  
  <p>As suggested in <a href="https://stackoverflow.com/questions/44173831/codesign-returned-unknown-error-1-ffffffffffffffff">Codesign returned unknown error -1=ffffffffffffffff</a> I added <code>set-key-partition-list -S apple-tool:,apple:,codesign: -s -k ${KEYCHAIN_PW} ${KEYCHAIN_PATH}</code> to my build script but it did not fix the issue.</p>
  
  <p>Do you have any idea how to address this issue? Why is there an existing signature to be replaced?</p>
  
  <p><strong>Update 1 - We keep getting the error after:</strong></p>
  
  <ul>
  <li>switching from <code>xbuild</code> to <code>msbuild</code> version 15.3.0.0</li>
  <li>setting jenkins keychain to <a href="https://stackoverflow.com/a/43157573/4739420">"Allow all applications to access this item"</a></li>
  <li>deleting the <a href="https://stackoverflow.com/a/44307605/4739420">derived data folder</a> </li>
  <li>not using relative paths for <a href="https://github.com/fastlane/fastlane/issues/8797" rel="nofollow noreferrer"><code>security</code> commands</a></li>
  </ul>
  
  <p>A similar problem is described in the <a href="https://forums.developer.apple.com/thread/64101" rel="nofollow noreferrer">Apple forum</a>.</p>