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

Ubuntu下Monogame项目无法运行/装NuGet包:NUnit.nupkg不存在

解决MonoGame MGDesktopGL项目的NuGet还原错误

核心问题分析

你遇到的错误分为两类:一是本地NUnit包路径识别失败,二是MonoGame工具包(dotnet-mgcb、dotnet-mgcb-editor-windows)还原失败。前者大概率是NuGet本地源配置错误,后者是跨平台工具不匹配(从路径判断你处于Linux环境,却尝试还原Windows专属工具)。


分步解决方案

1. 修正NuGet本地源配置

NuGet本地源需要指向包含nupkg文件的文件夹,而非单个nupkg文件路径。执行以下操作:

  • 查看当前NuGet源列表:
    nuget sources list
    
  • 如果存在指向/path/to/NUnit.3.13.3/NUnit.3.13.3.nupkg的错误源,删除它:
    nuget sources remove -name "错误源名称"
    
  • 添加包含NUnit包的文件夹作为本地源:
    nuget sources add -name "LocalNUnit" -source "/path/to/NUnit.3.13.3/"
    

2. 清理NuGet缓存

缓存损坏可能导致路径识别异常,执行清理命令:

dotnet nuget locals all --clear

清理完成后重新执行还原:

dotnet restore

3. 替换跨平台不兼容的MonoGame工具包

你在Linux环境中尝试还原dotnet-mgcb-editor-windows(Windows专属工具)必然失败,需修改工具清单文件:

  • 打开项目根目录下的.config/dotnet-tools.json
  • 删除包含dotnet-mgcb-editor-windows的条目,添加Linux版本工具:
    {
      "version": 1,
      "isRoot": true,
      "tools": {
        "dotnet-mgcb": {
          "version": "3.8.1.303",
          "commands": ["mgcb"]
        },
        "dotnet-mgcb-editor-linux": {
          "version": "3.8.1.303",
          "commands": ["mgcb-editor"]
        }
      }
    }
    
  • 重新还原工具:
    dotnet tool restore
    

4. 验证项目文件包引用

打开项目的.csproj文件,确认NUnit引用版本与本地包一致,且未硬编码错误路径:

<PackageReference Include="NUnit" Version="3.13.3" />

5. 同步Rider配置

  • 清除Rider缓存:点击File → Invalidate Caches...,勾选Clear file system cache and local history,重启Rider。
  • 确认Rider使用系统dotnet SDK:进入Settings → Build, Execution, Deployment → Toolset and Build,确保.NET CLI executable指向/usr/lib/dotnet/dotnet。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 10:35:19