我有一个相当简单的 .NET MAUI 应用程序,我正在 Win10 上的 Visual Studio 中开发它,然后通过在模拟器中运行它来测试它。它工作得很好,直到我将目标框架从 .NET7 升级到 .NET8。
现在启动前就显示这个错误:
“调试目标
不是 与活动目标框架Pixel 5 - API 34 (Android 14.0 - API 34)
兼容,请选择一个iOS
的有效调试目标。”iOS
我知道它出于某种原因试图在我的 Android 模拟器中加载 iOS 版本,但我不知道如何解决这个问题。我浏览了项目属性中的选项,看到了完全禁用 iOS 构建的可能性,但我不希望这样 - 我希望我的应用程序能够在 Android 和 iOS 上运行。
我在这里做错了什么?
csproj
文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android33.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<ImplicitUsings>enable</ImplicitUsings>
<SingleProject>true</SingleProject>
<RootNamespace>MyAPp</RootNamespace>
<!-- Display name -->
<ApplicationTitle>MyAPp</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.ppg.MyAPp</ApplicationId>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net7.0-ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net7.0-android'">21.0</SupportedOSPlatformVersion>
<UseInterpreter Condition="$(TargetFramework.Contains('-ios')) AND '$(Configuration)' == 'Release'">True</UseInterpreter>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DevExpress.Maui.CollectionView" Version="23.1.6" />
<PackageReference Include="DevExpress.Maui.Core" Version="23.1.6" />
<PackageReference Include="DevExpress.Maui.DataGrid" Version="23.1.6" />
<PackageReference Include="DevExpress.Maui.Controls" Version="23.1.6" />
<PackageReference Include="DevExpress.Maui.Editors" Version="23.1.6" />
<ProjectReference Include="..\MyAPp.API.Models\MyAPp.API.Models.csproj" />
<ProjectReference Include="..\MyAPp.Entities\MyAPp.Entities.csproj" />
<TrimmableAssembly Include="DevExpress.Data.v23.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Views\ArticleDetailPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ArticleListPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\DocDetailPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\DocItemPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\SettingsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\StoreDocsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
</Project>
您的问题是您使用了不正确的 TargetFramework
<TargetFrameworks>net8.0-ios;net8.0-android33.0</TargetFrameworks>
应该看起来像这样:
<TargetFrameworks>net8.0-ios;net8.0-android</TargetFrameworks>