.NET7 MAUI应用在iOS16/Xcode14环境下无法调试与发布
问题描述
- Mac Catalyst可正常调试,但iOS模拟器无法调试,应用输出报错:
xcodebuild[4480:64944] Writing error result bundle to /var/folders/wh/z7x5swm90fb6f6cxfp39760h0000gn/T/ResultBundle_2022-30-10_10-46-0020.xcresult xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" cannot be located. xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find simctl 2> /dev/null' failed with exit code 16384: (null) (errno=Invalid argument) xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
- 使用环境:Visual Studio 17.4(预览版5,版本号17.4 build 2339)、Xcode 14.0.1(对应iOS 16 SDK)
- 已检查VS「偏好设置>SDK位置>Apple」,配置看似正常,但作为Mac新手,怀疑遗漏设置
- 执行发布命令时VS崩溃:
dotnet publish -f:net7.0-ios -c:Release
更新:
- 降级到net6.0后错误依旧
- 安装Xamarin.Mac后问题未解决
- 组件版本详情:
- Xamarin.iOS Version: 16.0.0.72 (Visual Studio Community)
- Xcode 14.0.1 (21336)
- Xamarin.Mac Version: 8.12.0.2 (Visual Studio Community)
- 已确认错误中引用的
MacOSX.sdk目录存在,但不确定目录结构是否符合要求
解决方案
- 校准Xcode命令行工具路径
- 打开终端,执行
xcode-select -p,检查输出是否为/Applications/Xcode.app/Contents/Developer - 若路径不符,执行
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer强制设置正确路径
- 打开终端,执行
- 验证Xcode SDK配置与权限
- 打开Xcode,进入「偏好设置>Locations」,确认「Command Line Tools」选项选中的是Xcode 14.0.1
- 终端执行
ls -ld /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk,检查目录权限(正常应为所有者root,组admin,权限drwxr-xr-x),若权限异常,执行sudo chmod -R 755 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk修复
- 重置Visual Studio缓存与配置
- 完全关闭Visual Studio
- 终端执行以下命令删除相关缓存:
rm -rf ~/Library/Caches/VisualStudio/17.0 rm -rf ~/Library/Caches/Xamarin - 重新打开Visual Studio,再次检查「偏好设置>SDK位置>Apple」,确认自动识别到正确的Xcode路径
- 排查项目与dotnet环境问题
- 在项目根目录执行
dotnet clean && dotnet restore,清理并重新还原项目依赖 - 用Xcode直接打开项目生成的
.xcodeproj文件(通常在obj/Release/net7.0-ios/ios-arm64目录下),尝试运行iOS模拟器,若Xcode也无法运行,说明是Xcode本身的问题,可尝试重装Xcode
- 在项目根目录执行
- 定位发布崩溃原因
- 执行带详细日志的发布命令:
dotnet publish -f:net7.0-ios -c:Release -v diag - 查看日志中崩溃前的报错信息,针对性修复(比如证书配置、目标版本不兼容等)
- 执行带详细日志的发布命令:
内容的提问来源于stack exchange,提问作者Jimmy
相关产品推荐
相关产品推荐

