You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8 Maui升级后NuGet包缺失无法安装求助

.NET Maui 7升级到8后NuGet缺失及iOS目标框架错误修复方案

问题根源分析

从你的csproj文件能看到几个核心问题:

  • TargetFrameworks混合了.NET7和.NET8版本(比如net7.0-maccatalyst和net8.0-ios并存)
  • NuGet包版本不兼容,部分包还是.NET7版本(比如Microsoft.Maui.Controls.Maps是7.0.52,而Microsoft.Maui.Controls已经是8.0.3)
  • 项目配置里还保留了大量.NET7目标框架的专属PropertyGroup,导致restore时无法正确生成net8.0-ios的资产文件

分步修复方案

1. 统一所有目标框架到.NET8

修改<PropertyGroup>里的TargetFrameworks,把所有net7开头的框架替换成net8:

<TargetFrameworks>net8.0-maccatalyst;net8.0-ios;net8.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

同时删除或修改所有针对net7.0-*的配置PropertyGroup,比如把:

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-android|AnyCPU'">
  ...
</PropertyGroup>

全部替换成net8.0-*的对应配置,或者如果这些配置内容和全局一致,可以直接删除重复项。

另外,把iOS专属配置的目标框架也改成net8:

<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
  <ProvisioningType>automatic</ProvisioningType>
  <CodesignKey>Apple Development: Created via API (96CKZSNPV8)</CodesignKey>
  <CodesignProvision>VS: net.popupmobile.popupshop Development</CodesignProvision>
</PropertyGroup>

2. 更新NuGet包到.NET8兼容版本

修改<ItemGroup>里的PackageReference,确保所有包版本适配.NET8:

<ItemGroup>
    <PackageReference Include="CommunityToolkit.Maui" Version="8.0.0" />
    <PackageReference Include="Microsoft.AppCenter" Version="5.0.1" />
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.1" />
    <PackageReference Include="Microsoft.Azure.NotificationHubs" Version="4.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
    <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
    <PackageReference Include="Microsoft.Maui.Controls.Maps" Version="8.0.3" />
    <PackageReference Include="Plugin.Fingerprint" Version="3.0.0-beta.1" />
    <PackageReference Include="Telerik.UI.for.Maui" Version="6.0.0" />
</ItemGroup>

3. 彻底清理并重新还原项目

执行以下命令(在项目根目录):

  • 手动删除bin和obj文件夹,或用命令:
rm -r bin obj # Linux/macOS
rd /s /q bin obj # Windows命令行
  • 清理项目:
dotnet clean
  • 重新还原NuGet包:
dotnet restore
  • 尝试构建项目:
dotnet build

4. 验证iOS目标框架配置

确保iOS的RuntimeIdentifier配置正确,保留现有配置即可:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>

完成以上步骤后,项目的NuGet包缺失问题和iOS目标框架错误应该能解决。

内容的提问来源于stack exchange,提问作者Cef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 12:50:53