8

I'm trying to debug my Xamarin.Forms application on a physical iPhone, from my windows machine.

  • I have a Mac connected, and an iPhone connected to that Mac
  • I have an Apple developer certificate
  • I have the device linked to my developer account
  • I set up automatic provisioning using Visual Studio (17.0.5)
  • I downloaded the generated certificate, and installed it:
    • On the Mac in the System keychain and Login keychain
    • On my windows machine running Visual Studio

When I try to deploy my application in Debug|iPhone, I get the following error:

iOS code signing key 'Apple Development: John Doe (5L4565FZ2L)' not found in keychain.

More details from the build output in Visual Studio:

2>Using "DetectSigningIdentity" task from assembly "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\iOS\..\iOS\Xamarin.iOS.Tasks.dll".
2>Task "DetectSigningIdentity"
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9039262+01:00 - Started
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9039262+01:00 - Initializing
2>  [xma]: Trying to get a Build Connection for Session '6b535ab5f3c9b550fa521b36f236660807d516f929527c4e1cb2a3ecca9ec40d': Xamarin.Messaging.Build.Client.BuildConnection.6b535ab5f3c9b550fa521b36f236660807d516f929527c4e1cb2a3ecca9ec40d, Lifetime: AppDomain
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9039262+01:00 - Initialized
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9039262+01:00 - There's no available inputs to copy to the Mac
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9039262+01:00 - Serializing intputs
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9079268+01:00 - Executing
2>  [xma]: Starting remote task execution for 'Writeful.Mobile.iOS': Xamarin.iOS.Tasks.DetectSigningIdentity
2>  [xma]: Sending Request Xamarin.Messaging.Build.Contracts.ExecuteTaskMessage to topic xvs/build/execute-task/Writeful.Mobile.iOS/6b535ab002fDetectSigningIdentity
2>  [xma]: Received Response of Xamarin.Messaging.Build.Contracts.ExecuteTaskMessage to topic build6b535ab5f3c9b550fa521b36f236660807d516f929527c4e1cb2a3ecca9ec40d47080johndoe/+/xvs/build/execute-task/Writeful.Mobile.iOS/6b535ab002fDetectSigningIdentity
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9499278+01:00 - Logging messages
2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(1566,3): error : iOS code signing key 'Apple Development: John Doe (5L4565FZ2L)' not found in keychain.
2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(1566,3): error :         
2>  DetectSigningIdentity: 2022-02-06T17:49:30.9499278+01:00 - Finished
2>Done executing task "DetectSigningIdentity" -- FAILED.
2>Done building target "_DetectSigningIdentity" in project "Writeful.Mobile.iOS.csproj" -- FAILED.
2>
2>Build FAILED.
2>
2>"C:\Users\johndoe\source\repos\johndoe\writeful-app\Writeful.Mobile.iOS\Writeful.Mobile.iOS.csproj" (Build;BuiltProjectOutputGroup;BuiltProjectOutputGroupDependencies;DebugSymbolsProjectOutputGroup;DebugSymbolsProjectOutputGroupDependencies;DocumentationProjectOutputGroup;DocumentationProjectOutputGroupDependencies;SatelliteDllsProjectOutputGroup;SatelliteDllsProjectOutputGroupDependencies;SGenFilesOutputGroup;SGenFilesOutputGroupDependencies target) (1) ->
2>(_DetectSigningIdentity target) -> 
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(1566,3): error : iOS code signing key 'Apple Development: John Doe (5L4565FZ2L)' not found in keychain.
2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(1566,3): error :         
2>
2>    0 Warning(s)
2>    1 Error(s)
2>
2>Time Elapsed 00:00:01.23
========== Build: 1 succeeded, 1 failed, 21 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

I'm not sure which device is missing the signing key, but I assume it is the iPhone, since I installed the certificate on the Mac.

If this is the issue, how can I transfer the certificate to the iPhone? I already tried by deploying an empty app from Xcode on the Mac to the iPhone, but that didn't work.

Daan
  • 197
  • 1
  • 2
  • 11
  • It could be a potential issue with `VS for windows`, you can use `Vs for Mac` to deploy to actual device . – ColeX Feb 08 '22 at 08:41

6 Answers6

9

It took me a while to figure out this issue. I had to export the certificate from my mac to a .p12 file and import the certificate into VS > Tools > options > Xamarin > Apple accounts > View Details > Import certificate and then select the p12 file and import it into VS make sure it display Valid on the status column.

RBT
  • 24,161
  • 21
  • 159
  • 240
Alex Abreu
  • 101
  • 1
  • 1
  • Can you please elaborate in this answer as I believe it is probably the correct answer. How did you export it from the mac? – After_Sunset Jul 05 '22 at 17:49
  • 1
    Go to Launchpad -> Keychain Access and select "My Certificates" tab. Select the certificate you want to export from the list. Click on "File" menu and then on "Export Items" – Matias Masso Nov 03 '22 at 16:50
6

You would have to install both the development certificate AND the development provisioning profile on your Mac.

The easiest way to do this is by following the following steps:

  1. Download and install Xcode, you have probably already done this.
  2. Login into Xcode with your apple developer account: Xcode -> Preferences -> Account, use the + sign the add a new account.
  3. Once logged in Xcode will give you the option to Download Manual Profiles in the same view, click this and Xcode will do as promised. This can be done for each account and development team.
  4. Happy debugging!

Note: In Xcode projects (*.xcworkspace, Native iOS, Flutter, etc.) The easiest option is to click your top level app project (in xcode) and under Signing & Capabilities check the [ ] Automatically Manage Signing option.

You can also manually download the certificate and provisioning profile(s) from AppStoreConnect. Once downloaded, double click the files to install the certificate and profile. This should work, however, in my experience this can result in duplicate profiles and other weird issues. When using Visual Studio for Mac these are sometimes resolved by restarting VS for Mac or your machine. If issues persist, look in the following folder: ~/Library/MobileDevice/Provisioning Profiles here your installed profiles are listed. Finder will show you a preview with details if you select a provisioning profile. Delete duplicate profiles usually helps, these have different file names but the same profile details.

  • 2
    This is 100% correct, but just a note ... if you haven't compiled your application for a while, then certificate and/or development provisioning profile may have expired, in which case you will have to delete and recreate these. Also, if like me, you have moved to another macbook since you last compiled your application, you may have a certificate that is not expired, but has no private key in your keychain - in which case you also will need to delete and recreate the certificate and/or profile – BruceHill Oct 12 '22 at 11:55
  • Also, if your app is in the app store, then deleting/recreating the certificates and profile has no effect on the app in the store. For enterprise accounts, though, revoking and recreating the certificate will affect existing deployed applications. Take a look at this question: https://stackoverflow.com/q/6320255/649497 – BruceHill Oct 12 '22 at 11:59
1

I'm using Maui, and in my case this error came followed by the sentence "Please enable automatic provisioning from the ios bundle signing page".
So right click your project on Solution Explorer, click on Properties, expand iOS node, and select "Bundle Signing".
Under "Scheme" caption you'll find a dropdown; change "Manual Provisioning" to "Automatic Provisioning" and you are done.

Matias Masso
  • 1,670
  • 3
  • 18
  • 28
0

You can workaround the issue by removing the flag from the debug builds in the .csproj file. Try to follow this link : Check

Amjad S.
  • 1,196
  • 1
  • 4
  • 16
0

it might be VS issue. Please refer this official Link where issue is fixed. Please make sure you're using latest version. Check Here

Krunal Bagadia
  • 419
  • 2
  • 8
  • I'm using VS 17.0.5 (currently latest). I tried the workaround using manual provisioning, but it makes no difference – Daan Feb 07 '22 at 08:38
0

Had a similar problem with same error but for an existing project. The provisioning profiles were new because of an expired certificate. But the new valid ones were in the keychain.

Anyway, what worked for me was to turn off Hot Restart in VS->Tools->Options->Xamarin->iOS settings

Seems like it was holding on to the old certificates somehow. The clue was they kept reappearing in the keychain after I deleted them when I reconnected.

May not help OP but may help others with similar problem.

nick66
  • 57
  • 4
  • ?? Mark down? It fixed the problem. If it doesn't work for you move on? Or explain why – nick66 Oct 13 '22 at 08:14
  • I just want to say THANK YOU!!! I would have never thought of this but, given how broken everything net6-iOS has been since the net7 updates, having someone actually have a helpful answer - about such an esoteric thing - has been wonderful! – baskren Dec 16 '22 at 20:26