MAUI项目编译报错WMC0621:无法解析GenXbf.dll路径
错误信息
Error WMC0621 Cannot resolve 'GenXbf.dll' under path
'C:\Users\knocte\Documents\Code\RIM\packages\microsoft.windowsappsdk\1.2.221209.1\buildTransitive..\tools\net472..\x64\genxbf.dll'.
Please ensure that the Nuget was properly restored and that the path
is available on
disk. Frontend C:\Users\knocte\Documents\Code\RIM\packages\microsoft.windowsappsdk\1.2.221209.1\tools\x64\genxbf.dll 1
项目相关配置片段
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041</TargetFrameworks> ... <SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</SupportedOSPlatformVersion> <TargetPlatformMinVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</TargetPlatformMinVersion> </PropertyGroup> <ItemGroup Condition="$(TargetFramework.Contains('-windows'))"> <!-- Required? - WinUI does not yet have buildTransitive for everything --> <PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.5.1" /> <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.221209.1" /> </ItemGroup>
解决步骤
强制重新还原NuGet包
- 右键解决方案 → 管理解决方案的NuGet程序包,点击「还原」按钮;或者在项目根目录终端运行
dotnet restore。 - 检查路径
C:\Users\knocte\Documents\Code\RIM\packages\microsoft.windowsappsdk\1.2.221209.1\tools\x64\下是否存在genxbf.dll,如果不存在,手动删除该版本的Windows App SDK包文件夹后再次执行还原。
- 右键解决方案 → 管理解决方案的NuGet程序包,点击「还原」按钮;或者在项目根目录终端运行
清理并重建项目
在Visual Studio中执行「生成」→「清理解决方案」,随后执行「生成解决方案」;或终端依次运行dotnet clean和dotnet build。调整Windows App SDK版本兼容性
当前项目基于.NET 7,Windows App SDK 1.2.221209.1可能存在兼容性问题。尝试修改项目文件中的PackageReference版本,升级到与.NET 7兼容的最新稳定版(如1.4.x系列),或降级到1.2分支的其他稳定版本,修改后重新还原包并编译。修正MSBuild路径解析
在项目的PropertyGroup节点中添加显式路径配置,帮助MSBuild正确定位工具文件:<WindowsAppSDKToolsPath Condition="$(TargetFramework.Contains('-windows'))">$(NuGetPackageRoot)microsoft.windowsappsdk\1.2.221209.1\tools\x64</WindowsAppSDKToolsPath>修复Visual Studio组件
打开Visual Studio安装器,检查是否已安装「Windows App SDK」相关组件(在.NET桌面开发 workload下),若缺失则添加该组件;或选择「修改」→「修复」Visual Studio安装。
内容的提问来源于stack exchange,提问作者knocte

