.NET MAUI iOS模拟器报错:Info.plist无有效CFBundleVersion
问题描述
现有.NET MAUI应用在Android和Windows环境运行正常,但在iOS模拟器启动时,VS Code抛出以下错误:
The application's Info.plist does not contain a valid CFBundleVersion.
Ensure your bundle contains a valid CFBundleVersion.
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):
Simulator device failed to install the application.
The application's Info.plist does not contain a valid CFBundleVersion.
Ensure your bundle contains a valid CFBundleVersion.
Underlying error (domain=NSPOSIXErrorDomain, code=22):
Failed to install the requested application
The application's Info.plist does not contain a valid CFBundleVersion.
error HE0046: Failed to install the app '***' on the device 'iOS 17.2': simctl returned exit code 22
已尝试的排查操作:
- 重置模拟器
- 切换不同模拟器设备测试
- 手动添加CFBundleVersion配置
- 复制可正常运行的示例应用的资源文件夹结构及内容
当前项目的版本配置:
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> <ApplicationVersion>1</ApplicationVersion>
也曾尝试修改格式:将ApplicationDisplayVersion调整为最多3个点的格式(如1.0.0.1),ApplicationVersion改为最多4位数字(1、20、301、4321),问题仍未解决。
解决方案建议
1. 检查Info.plist的自动映射冲突
.NET MAUI会自动将ApplicationVersion映射为CFBundleVersion,ApplicationDisplayVersion映射为CFBundleShortVersionString,手动添加的同名配置可能导致冲突:
- 打开
Platforms/iOS/Info.plist,删除手动添加的CFBundleVersion或CFBundleShortVersionString标签,让MAUI自动从项目配置生成。 - 确认Info.plist无格式错误(如标签未闭合、值为空等)。
2. 清理重建项目
执行以下命令清理缓存并重建:
dotnet clean dotnet restore
同时删除项目目录下的bin和obj文件夹,再重新构建运行。
3. 确认版本配置的全局有效性
确保ApplicationDisplayVersion和ApplicationVersion配置在项目文件(.csproj)的全局<PropertyGroup>节点下,未被条件编译限制(如仅针对Android/Windows):
<PropertyGroup> <ApplicationId>com.yourcompany.yourapp</ApplicationId> <ApplicationDisplayVersion>1.0.0</ApplicationDisplayVersion> <ApplicationVersion>1</ApplicationVersion> <!-- 其他全局配置 --> </PropertyGroup>
4. 验证生成的Info.plist内容
构建完成后,找到生成的Info.plist文件(路径通常为bin/Debug/net8.0-ios/iossimulator-x64/YourApp.app/Info.plist),检查以下两个字段是否正确生成:
<key>CFBundleVersion</key> <string>1</string> <key>CFBundleShortVersionString</key> <string>1.0.0</string>
若字段缺失或格式错误,需排查项目文件的配置逻辑是否存在问题。
5. 更新.NET MAUI SDK
旧版本SDK可能存在iOS版本映射bug,尝试更新至最新稳定版:
dotnet workload update maui
内容的提问来源于stack exchange,提问作者Jonnathan Sierra

