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

升级.NET MAUI包遇NU1605错误:无法同时更新Controls与Compatibility版本

解决.NET MAUI中NU1605包降级错误(同步升级Microsoft.Maui.Controls与Compatibility)

问题场景

针对.NET 8的MAUI项目,尝试将Microsoft.Maui.Controls和Microsoft.Maui.Controls.Compatibility从8.0.3同步升级到8.0.6时触发NU1605错误,仅能单独升级其中一个包,升级第二个时就会提示包降级警告转错误:

Error NU1605 Warning As Error: Detected package downgrade: Microsoft.Maui.Controls from 8.0.6 to 8.0.3. Reference the package directly from the project to select a different version.
MyApp -> Microsoft.Maui.Controls.Compatibility 8.0.6 -> Microsoft.Maui.Controls (>= 8.0.6)
MyApp -> Microsoft.Maui.Controls (>= 8.0.3) MyApp

解决方案

1. 清理NuGet本地缓存

关闭Visual Studio,打开命令提示符执行以下命令,清除本地NuGet缓存中的旧版本包,避免缓存干扰:

dotnet nuget locals all --clear

2. 手动编辑项目文件(.csproj)

找到项目的.csproj文件,用文本编辑器打开,将Microsoft.Maui.Controls和Microsoft.Maui.Controls.Compatibility的引用统一修改为显式指定8.0.6版本,替换原有的Update节点为Include节点:

<ItemGroup>
  <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
  <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
</ItemGroup>

说明:Microsoft.Maui.Controls.Compatibility与Microsoft.Maui.Controls是强绑定的配套包,必须使用完全相同的版本。显式指定版本可以强制NuGet使用目标版本,避免依赖解析时的版本冲突。

3. 重新还原NuGet包

保存项目文件后,重新打开Visual Studio,右键点击项目选择「还原NuGet包」,或者在命令提示符执行:

dotnet restore

额外检查

如果项目是解决方案的一部分,检查其他依赖该MAUI项目的子项目,确保这些项目中的Microsoft.Maui.Controls相关包版本也同步升级到8.0.6,避免跨项目的依赖版本不匹配。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 14:47:17