该应用程序没有启用钥匙串访问组

The application has no keychain access groups enabled

我们有一个 Xamarin.Forms 应用程序,正在尝试使用 MSAL 身份验证,但遇到 iOS 项目的问题。它在模拟器中工作,但当由 Azure 管道构建并安装在真实 iPhone 上时,发生异常:

MSAL.Xamarin.iOS.4.14.0.MsalClient Exception: ErrorCode: missing_entitlements Microsoft.Identity.Client.MsalClientException: The application does not have keychain access groups enabled in the Entitlements.plist. As a result, there was a failure to save to the iOS keychain. The keychain access group "OURID.com.microsoft.adalcache' is not enabled in the Entitlements.plist...

OURID当然是对真实值的替代。

这是 entitlements.plist 中的内容:

 <key>keychain-access-groups</key>
  <array>
     <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
  </array>

在 B2CAuthenticationService 构造函数中:

            var builder = PublicClientApplicationBuilder.Create(B2CConstants.ClientID)
            .WithB2CAuthority(B2CConstants.AuthoritySignInSignUp)
            .WithIosKeychainSecurityGroup(B2CConstants.IOSKeyChainGroup)
            .WithRedirectUri($"msal{B2CConstants.ClientID}://auth");

我可以遗漏什么导致异常?

已添加:如果我将变量替换任务添加到管道中,即便如此,这些任务也只能替换 xml 和 json 配置文件中的值;不是 plist 文件。

我通过在文本编辑器中编辑项目并在

中指定 entitlements.plist 解决了这个问题
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>

在 属性 组内

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">

我之前通过项目 GUI 执行此操作时,它仅影响 属性 组

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">

这就是为什么它在模拟器中对我有效,但在真实设备上却无效。