为什么我的 iOS 生成会失败,并显示“在 keychain 中未找到有效的 iPhone 代码签名密钥”?Why does my iOS build fail with: no valid iPhone code signing keys found in keychain?

错误的原因Cause of the error

当有问题的项目正在查找有效的代码签名凭据但找不到它们时,会出现此错误消息。This error message occurs when the project in question is looking for valid code-signing credentials but are unable to find them. 在物理 iOS 设备上进行测试和部署需要进行代码签名;以及即席 & 应用商店版本。Code signing is required for testing and deployments on physical iOS devices; as well as Ad-hoc & App store builds.

预配设备Provisioning Devices

如果你之前未预配 iOS 设备,以下指南将指导你完成完整的分步过程:设备预配指南If you haven't provisioned an iOS device before, the following guide will take you through the full step-by-step process: Device Provisioning Guide

使用 iOS 模拟器时的 BugBug when using iOS Simulator

备注

此问题已在最新版本的 Xamarin for Visual Studio 中得到解决。This issue has been resolved in recent versions of Xamarin for Visual Studio. 但是,如果该软件的最新版本发生问题,请使用完整的版本信息和完整的生成日志输出来记录新的 bugHowever, if the issue occurs on the latest version of the software, please file a new bug with your full versioning information and full build log output.

Xamarin 中存在 bug。 Visual Studio 3.11 导致了 Xamarin. Forms 模板中的 iOS 项目,以将 codesign info.plist 添加到模拟器生成;使用模拟器有效地阻止测试。There was a bug in Xamarin.Visual Studio 3.11 which caused the iOS project in a Xamarin.Forms template to add the codesign Entitlements.plist to Simulator builds; effectively blocking testing using the Simulator.

如何修复How to fix

可以通过从 .csproj 文件中的调试生成中删除 <CodesignEntitlements> 标志来解决该问题。You can workaround the issue by removing the <CodesignEntitlements> flag from the debug builds in the .csproj file. 你可以按如下所示进行操作:You can do this as follows:

警告

.Csproj 文件中的错误可能会破坏您的项目,因此在尝试此操作之前,最好先备份您的文件。Errors in .csproj files can break your project, so it's a good idea to backup your files before attempting this.

  1. 在解决方案窗格中右键单击 iOS 项目,然后选择 "卸载项目"Right click the iOS project in the solution pane and select Unload Project
  2. 再次右键单击该项目,然后选择 "编辑 [项目名称] .csproj "Right click the project again and select Edit [ProjectName].csproj
  3. 找到调试 PropertyGroups,它们应以如下所示的标志开头:Locate the Debug PropertyGroups, they should start with flags that look like this:
    • 调试: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">Debug: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
    • 版本: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">Release: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
  4. 在使用模拟器的每个版本中,删除或注释掉以下属性: <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>In each of the builds that use the simulator, delete or comment out the following property: <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
  5. 重载项目,你应该能够部署到模拟器。Reload the project and you should be able to deploy to the simulator.

后续步骤Next Steps

若要获得更多帮助,请联系我们,或者,如果在使用上述信息后仍出现此问题,请参阅哪些支持选项可用于 Xamarin?有关联系人选项、建议的信息,以及如何在需要时记录新 bug.For further assistance, to contact us, or if this issue remains even after utilizing the above information, please see What support options are available for Xamarin? for information on contact options, suggestions, as well as how to file a new bug if needed.