发布MAUI应用时遇Duplicate assemblies encountered错误求助
解决MAUI Android发布时的重复程序集哈希错误
调试MAUI应用到Android设备一切正常,但发布时出现以下错误:
Duplicate 32-bit hash 0x2159891885 encountered for assembly Microsoft.Maui Duplicate 32-bit hash 0x2159891885 encountered for assembly Microsoft.Maui Duplicate 32-bit hash 0x2159891885 encountered for assembly Microsoft.Maui Duplicate 32-bit hash 0x3800979733 encountered for assembly Microsoft.Maui.Controls.Compatibility Duplicate 32-bit hash 0x3800979733 encountered for assembly Microsoft.Maui.Controls.Compatibility Duplicate 32-bit hash 0x3800979733 encountered for assembly Microsoft.Maui.Controls.Compatibility Duplicate 32-bit hash 0x2758225723 encountered for assembly Microsoft.Maui.Controls.Xaml Duplicate 32-bit hash 0x2758225723 encountered for assembly Microsoft.Maui.Controls.Xaml Duplicate 32-bit hash 0x2758225723 encountered for assembly Microsoft.Maui.Controls.Xaml Duplicate 32-bit hash 0x2480646305 encountered for assembly Microsoft.Maui.Controls Duplicate 32-bit hash 0x2480646305 encountered for assembly Microsoft.Maui.Controls Duplicate 32-bit hash 0x2480646305 encountered for assembly Microsoft.Maui.Controls Duplicate 32-bit hash 0x2861189240 encountered for assembly Microsoft.Maui.Essentials Duplicate 32-bit hash 0x2861189240 encountered for assembly Microsoft.Maui.Essentials Duplicate 32-bit hash 0x2861189240 encountered for assembly Microsoft.Maui.Essentials XABLD7009: System.InvalidOperationException: Duplicate assemblies encountered
使用环境:Visual Studio Community 2022 17.5.1,项目依赖Plugin.Maui.Audio和Community Toolkit。
以下是可行的解决步骤:
- 清理项目与解决方案:右键解决方案选择「清理解决方案」,再右键项目选择「清理」,手动删除项目目录下的
bin和obj文件夹,重启Visual Studio后重新尝试发布。 - 统一NuGet包版本:打开NuGet包管理器,确保所有MAUI核心包(Microsoft.Maui.*)、Plugin.Maui.Audio、Community Toolkit的版本完全一致,避免版本冲突导致重复引用。
- 调整发布配置:右键Android项目→属性→发布→高级,暂时取消勾选「启用代码收缩(R8)」,同时检查目标架构设置,避免重复架构的引用。
- 编辑项目文件:打开项目的
.csproj文件,移除重复的<PackageReference>节点,在<PropertyGroup>中添加以下配置:<AndroidUseAapt2>true</AndroidUseAapt2> <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot> - 更新Visual Studio:17.5.1版本存在部分MAUI发布的已知问题,升级到最新稳定版可修复兼容性问题。
内容的提问来源于stack exchange,提问作者Mike Tsayper
相关产品推荐
相关产品推荐

