Xamarin iOS应用提示缺少CFBundleIdentifier,但info.plist中已配置该字段
问题详情
运行Xamarin iOS应用MyCoffeeApp.iOS时,收到以下错误:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.Shared.targets(3,3): Error: A bundle identifier is required. Either add an 'ApplicationId' property in the project file, or add a 'CFBundleIdentifier' entry in the project's Info.plist file. (MyCoffeeApp.iOS)
已确认Info.plist中CFBundleIdentifier字段存在,但错误依旧。
可行解决方案
检查Info.plist的源代码格式
可视化编辑器显示的内容可能和实际XML代码不一致,右键Info.plist选择"打开方式"→"源代码编辑器",确认CFBundleIdentifier的节点格式正确,示例如下:<key>CFBundleIdentifier</key> <string>com.yourcompany.MyCoffeeApp</string>确保节点无拼写错误,字符串值不为空。
直接在项目文件中配置ApplicationId
右键iOS项目选择"卸载项目",再右键项目文件(.csproj)选择"编辑",在<PropertyGroup>节点中添加:<ApplicationId>com.yourcompany.MyCoffeeApp</ApplicationId>保存后重新加载项目,该配置会覆盖Info.plist中的对应字段,同时能让Xamarin构建工具正确识别。
清理重建项目
按以下步骤操作:- 执行菜单→"生成"→"清理解决方案"
- 删除iOS项目下的
bin和obj文件夹 - 重启开发工具(Visual Studio for Mac/Windows)
- 重新构建并运行项目
检查构建配置对应的Info.plist路径
有些项目会为Debug/Release等不同配置指定不同的Info.plist文件,检查项目属性→"iOS应用程序"→"Info.plist"路径是否指向你配置了CFBundleIdentifier的文件。
内容的提问来源于stack exchange,提问作者Adi Vizgan

