Xcode 14.2环境下兼容的.NET 7版本是哪个?
问题描述
当前开发环境:
- MacOS 12.7.2
- Xcode 14.2
- Visual Studio for Mac 17.6.7
- 已安装.NET 7 SDK版本:
7.0.100、7.0.311
已在解决方案根目录添加global.json控制SDK版本:
{ "sdk": { "version": "7.0.100", "rollForward": "disable", "allowPrerelease": false } }
项目文件配置:
<TargetFramework>net7.0-ios</TargetFramework> <SupportedOSPlatformVersion>14.0</SupportedOSPlatformVersion>
构建时出现错误:
This version of Microsoft.iOS requires the iOS 16.4 SDK (shipped with
Xcode 14.3). Either upgrade Xcode to get the required header files or
set the managed linker behaviour to Link Framework SDKs Only (to try
to avoid the new APIs).
由于MacOS Monterey无法安装Xcode 14.3,且调整链接器设置无效,询问应使用哪个.NET 7版本才能成功构建。
解决方案
需将.NET 7 SDK版本切换为7.0.306及之前的.NET 7补丁版本,推荐直接锁定7.0.306。
原因:.NET 7的7.0.307及后续补丁版本(包括当前的7.0.311)对应的Microsoft.iOS版本依赖Xcode 14.3的iOS 16.4 SDK;而7.0.306及更早的.NET 7版本适配的是Xcode 14.2的iOS 16.2 SDK,完全匹配当前环境。
修改global.json文件,指定版本为7.0.306:
{ "sdk": { "version": "7.0.306", "rollForward": "disable", "allowPrerelease": false } }
若机器未安装7.0.306,可通过以下命令安装:
dotnet install-sdk 7.0.306
内容的提问来源于stack exchange,提问作者TheUnexpected
相关产品推荐
相关产品推荐

