iOS 在钥匙串中找不到代码签名密钥“?Apple Distribution:我的名字 (xxxxxx)”

iOS code signing key '?Apple Distribution: My Name (xxxxxx)' not found in keychain

环境:
Windows 10 家,21H2
VS 版本 17.3.0 预览版 1.1

我已按照以下步骤解决此错误:

<PropertyGroup>
    <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
    <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
    <!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
    <OutputType>Exe</OutputType>
    <RootNamespace>MauiApp1</RootNamespace>
    <UseMaui>true</UseMaui>
    <SingleProject>true</SingleProject>
    <ImplicitUsings>enable</ImplicitUsings>

    <!-- Display name -->
    <ApplicationTitle>MauiApp1</ApplicationTitle>

    <!-- App Identifier -->
    <ApplicationId>com.testapp.maui</ApplicationId>
    <ApplicationIdGuid>CE4B9160-2B17-4559-8E4C-EA410A9A7966</ApplicationIdGuid>

    <!-- Versions -->
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
    <ApplicationVersion>1</ApplicationVersion>

    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
    <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
    <CodesignKey>‌Apple Distribution: My Name (xxxxxxx)</CodesignKey>
    <CodesignProvision>Apple Provisioning</CodesignProvision>


    <ArchiveOnBuild>true</ArchiveOnBuild>
    <TcpPort>58181</TcpPort>
    <ServerAddress>xxxxx</ServerAddress>
    <ServerUser>xxxxx</ServerUser>
    <ServerPassword>xxxxx</ServerPassword>
    <_DotNetRootRemoteDirectory>/Users/xxxxx/Library/Caches/Xamarin/XMA/SDKs/dotnet/</_DotNetRootRemoteDirectory>

</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
  <BuildIpa>True</BuildIpa>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
  <BuildIpa>True</BuildIpa>
</PropertyGroup>

<ItemGroup>
    <!-- App Icon -->
    <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

    <!-- Splash Screen -->
    <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

    <!-- Images -->
    <MauiImage Include="Resources\Images\*" />
    <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />

    <!-- Custom Fonts -->
    <MauiFont Include="Resources\Fonts\*" />

    <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
    <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

错误

iOS code signing key '?Apple Distribution: My Name (xxxxxx)' not found in keychain.

Code signing must be enabled to create an Xcode archive.

之前

另请注意,错误'?Apple Distribution: My Name (xxxxxx)'中有一个问号,我不知道它来自哪里。

更新:

我在构建期间使用此命令创建了一个日志文件

dotnet publish -f:net6.0-ios -c:Release /bl:msbuild.binlog

可以使用此工具查看日志文件:https://msbuildlog.com/

在此日志文件中,错误消息没有问号。所以我猜问号只是写日志信息时的显示错误。

然后在 binlog 中,它的字面意思是这样的:

The certificate 'Apple Distribution: My Name (xxx)' does not match 'Apple Distribution: My Name (xxx)‌'.

我已经逐个检查了。 完全相同的字符串。

我也注意到,它确实从服务器下载了证书,因为我可以在二进制日志中看到它们在条目“DetectingSigningIdentity”之后列出

我明白了,感谢最后的评论!

字符串

<CodesignKey>‌Apple Distribution: My Name (xxx)</CodesignKey>

包含一个隐藏角色。我无法在此 post 中重现此内容,因为隐藏字符已被过滤掉。

但它可以用字符串到十六进制转换器复制:https://online-toolz.com/tools/text-hex-convertor.php

输入这个十六进制代码:3ee2808c,它会产生这个字符“<”。当您键入 3e 时,它​​会产生相同的字符“<”。问题是当 copy/pasted 时,隐藏字符随之而来。

为了证明这一点,您只需 copy/paste 将第一个产品中的“<”再次输入到工具中即可。

查找字符“e2808c”,它代表一个“Zero-width non-joiner”
https://en.wikipedia.org/wiki/Zero-width_non-joiner
https://www.fileformat.info/info/unicode/char/200c/index.htm

这是怎么进入字符串的,我不知道。我也不知道字符串中可以隐藏字符!

然后这些隐藏字符串之一进入了我的 CodesignKey 标签,它不再匹配了。 Visual Studio 用问号正确指出了这一点。但是我对错误的解释是错误的,因为我没想到那里有我看不到的东西....