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

.NET MAUI发布失败:dotnet publish因缺失已弃用NuGet包报错

.NET MAUI发布失败:dotnet publish因缺失已弃用NuGet包报错

Goal

我正尝试通过VS Code的集成终端和.NET CLI发布已构建好的.NET MAUI应用,目标操作系统是Windows,使用win-x64 Runtime ID (RID)。

Problem

我可以正常使用dotnet build构建应用,Windows应用能成功编译到<Solution>\bin\Debug\net9.0-windows10.0.19041.0\win10-x64\<Solution>.dll路径。

但当运行dotnet publish -r win-x64 --output "<publishdir>"时,收到以下错误:

C:\<Solution Location>\<Solution>.csproj : error NU1102:
     Unable to find package Microsoft.NETCore.App.Runtime.Mono.win-x64 with version (= 9.0.2)
          - Found 104 version(s) in nuget.org [ Nearest version: 9.0.0-preview.7.24405.7 ]
          - Found 0 version(s) in C:\Program Files\dotnet\library-packs

What I've Tried

我尝试通过VS Code的NuGet: Add NuGet Package...命令、CLI命令以及手动添加包的方式,安装Microsoft.NETCore.App.Runtime.Mono.win-x64 NuGet包,但都没有成功。

这些方案失效的原因是,该包在9.0.0-preview.7.24405.7版本后就已被弃用;而我当前使用的.NET SDK版本是9.0.103:

PS C:\<Solution Location>> dotnet --list-sdks
9.0.103 [C:\Program Files\dotnet\sdk]

我确认过自己引用的NuGet包都没有依赖这个包,以下是项目的<ItemGroup>配置:

<ItemGroup>
    // compatible w/.NET 9 according to website
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" /> 
    // default MAUI Package
    <PackageReference Include="Microsoft.Maui.Controls" Version="9.0.40" /> 
    // default MAUI Package
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.2" />
    // does not have dependencies, according to Repository
    <PackageReference Include="QRCoder" Version="1.6.0" />
    // .NET system Package
    <PackageReference Include="System.Drawing.Common" Version="9.0.2" /> 
</ItemGroup>

根据我的调研和理解(我只是中级.NET用户,可能理解不到位),NuGet包管理器永远无法解决这个问题,因为它找不到满足=9.0.2版本要求的包。

我该如何解决这个问题? 可能我忽略了某个简单的方案,但目前找不到相关的错误排查信息。如果需要补充其他信息,请告诉我,我还在学习.NET框架,不太熟悉所有的最佳调试技巧。

备注:内容来源于stack exchange,提问作者Mason Ritchason

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 09:59:38