Azure Pipeline构建.NET 6 Xamarin iOS应用遇问题求助
基于.NET 6的Xamarin iOS Azure Pipeline构建问题解决方案
问题1:XamariniOS@2任务不识别net6.0-ios目标框架
报错信息:The TargetFramework value 'net6.0-ios' was not recognized
原因:XamariniOS@2任务针对传统Xamarin.iOS项目设计,依赖旧版MSBuild,不支持.NET 6的SDK风格iOS项目(这类项目属于.NET MAUI生态,需用dotnet命令构建)。
问题2:dotnet publish找不到有效签名证书
报错信息:No valid iOS code signing keys found in keychain
原因:证书安装到临时keychain后,dotnet publish未显式指定keychain路径,无法自动识别证书。
修正后的完整YAML配置
pool: vmImage: 'macOS-12' demands: - MSBuild steps: - task: InstallAppleCertificate@2 displayName: '安装Apple证书' inputs: certSecureFile: 'certificate.p12' certPwd: '$(P12password)' keychain: 'temp' keychainPassword: '$(P12password)' - task: InstallAppleProvisioningProfile@1 displayName: '安装Apple描述文件' inputs: provisioningProfileLocation: 'secureFiles' provProfileSecureFile: 'profile.mobileprovision' - task: UseDotNet@2 displayName: '安装.NET 6 SDK' inputs: packageType: 'sdk' version: 6.0.x - task: Bash@3 displayName: '安装.NET iOS工作负载' inputs: targetType: 'inline' script: | dotnet nuget locals all --clear dotnet workload restore --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json --source https://api.nuget.org/v3/index.json - task: Bash@3 displayName: '还原NuGet依赖' inputs: targetType: 'inline' script: | dotnet restore Sam.Com.sln - task: Bash@3 displayName: '构建并发布iOS应用' inputs: targetType: 'inline' script: | cd Sam.Com.iOS security unlock-keychain -p $(P12password) $HOME/Library/Keychains/temp.keychain-db dotnet publish -f net6.0-ios -c Release \ -p:ArchiveOnBuild=true \ -p:CodesignKey="iPhone Distribution: 你的证书名称" \ -p:CodesignProvision="你的描述文件名称" \ -p:Keychain=$HOME/Library/Keychains/temp.keychain-db
关键修改说明
- 移除XamariniOS@2任务:改用
dotnet publish命令直接构建,适配.NET 6 SDK风格项目。 - 调整工作负载源:将dotnet7的feed替换为dotnet6,确保安装对应版本的iOS工作负载。
- 解锁临时Keychain:在publish前添加
security unlock-keychain命令,让代码签名工具能访问临时keychain中的证书。 - 显式指定签名参数:在
dotnet publish中添加CodesignKey、CodesignProvision和Keychain参数,明确指定签名证书、描述文件和keychain路径。
内容的提问来源于stack exchange,提问作者SnapADragon
相关产品推荐
相关产品推荐

