.NET MAUI Blazor Hybrid iOS模拟器报错:Info.plist无有效CFBundleVersion
.NET MAUI Blazor Hybrid iOS模拟器启动报错:
The application's Info.plist does not contain a valid CFBundleVersion. 在Visual Studio 2022中开发.NET MAUI Blazor Hybrid应用,尝试在iOS模拟器运行时触发上述错误。已手动在Info.plist中添加CFBundleVersion配置,但问题仍未解决,且已尝试重置模拟器、更换测试设备等操作,仅模板新建项目可正常构建运行。
当前Info.plist配置
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>LSRequiresIPhoneOS</key> <true/> <key>UIDeviceFamily</key> <array> <integer>1</integer> <integer>2</integer> </array> <key>UIRequiredDeviceCapabilities</key> <array> <string>arm64</string> </array> <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>XSAppIconAssets</key> <string>Assets.xcassets/appicon.appiconset</string> <key>NSLocationWhenInUseUsageDescription</key> <string>We need access to your location to provide earthquake alerts for you.</string> <key>UIBackgroundModes</key> <array> <string>fetch</string> </array> <key>UIRequiresPersistentWiFi</key> <true/> <key>CFBundleVersion</key> <string>1.0</string> <key>CFBundleShortVersionString</key> <string>1</string> </dict> </plist>
错误日志
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22): Simulator device returned an error for the requested operation. 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 'com.companyname.shakesafe' on the device 'iOS 17.2 (21C62) - iPad Air (5th generation)': simctl returned exit code 22
项目.csproj配置
<Project Sdk="Microsoft.NET.Sdk.Razor"> <PropertyGroup> <TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks> <OutputType>Exe</OutputType> <RootNamespace>ShakeSafe</RootNamespace> <UseMaui>true</UseMaui> <SingleProject>true</SingleProject> <ImplicitUsings>enable</ImplicitUsings> <EnableDefaultCssItems>false</EnableDefaultCssItems> <Nullable>enable</Nullable> <!-- Display name --> <ApplicationTitle>ShakeSafe</ApplicationTitle> <!-- App Identifier --> <ApplicationId>com.companyname.shakesafe</ApplicationId> <!-- Versions --> <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> <ApplicationVersion>1</ApplicationVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'"> <CreatePackage>false</CreatePackage> <CodesignKey>iPhone Developer</CodesignKey> <MtouchDebug>true</MtouchDebug> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'"> <CreatePackage>false</CreatePackage> </PropertyGroup> <ItemGroup> <!-- App Icon --> <MauiIcon Include="Resources\AppIcon\appicon.svg" /> <!-- Splash Screen --> <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#99C24D" BaseSize="128,128" /> <!-- Images --> <MauiImage Include="Resources\Images\*" /> <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" /> <!-- Custom Fonts --> <MauiFont Include="Resources\Fonts\*" /> <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> </ItemGroup> <ItemGroup> <None Remove="Resources\Icons\report_icon.svg" /> <None Remove="Resources\Fonts\Nunito-VariableFont_wght.ttf" /> </ItemGroup> <ItemGroup> <Content Include="Resources\Icons\home_icon.svg"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> <Content Include="Resources\Icons\info_icon.svg"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> <Content Include="Resources\Icons\map_icon.svg"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> <Content Include="Resources\Icons\report_icon.svg"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> <Content Include="Resources\Icons\settings_icon.svg"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <!-- Necessary NuGet packages for MAUI --> <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.21" /> <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Microsoft.Maui.Maps" Version="8.0.21" /> <!-- Firebase packages --> <PackageReference Include="FirebaseAdmin" Version="2.4.1" /> <PackageReference Include="FirebaseDatabase.net" Version="4.2.0" /> </ItemGroup> <ItemGroup> <BundleResource Include="Resources\Fonts\Nunito-VariableFont_wght.ttf" /> </ItemGroup> <ItemGroup> <Content Update="wwwroot\data\gem_active_faults_harmonized.geojson"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <MauiAsset Update="Resources\Raw\AboutAssets.txt"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </MauiAsset> </ItemGroup> </Project>
解决方案
- 移除Info.plist中手动添加的版本字段:删除Info.plist里的
<key>CFBundleVersion</key>和<key>CFBundleShortVersionString</key>相关节点。MAUI的SingleProject模式会自动根据.csproj中的ApplicationVersion和ApplicationDisplayVersion生成这两个字段,手动添加可能导致冲突或被覆盖。 - 验证csproj版本格式:确保
ApplicationVersion和ApplicationDisplayVersion为合法格式,只能包含数字和点(例如1、1.0、1.0.1),无其他字符。当前csproj中的配置符合要求,但需保持一致性。 - 清理并重建项目:删除项目目录下的
bin和obj文件夹,重启Visual Studio,重新构建解决方案后再尝试启动iOS模拟器。
内容的提问来源于stack exchange,提问作者Güliz Hasan
相关产品推荐
相关产品推荐

