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

如何手动放置下载的NuGet包到指定文件夹供dotnet识别?

手动放置NuGet包到指定目录让dotnet识别的步骤

已完成的配置

你已经通过nuget.config指定了NuGet包存储目录:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value="/home/abc/scratch/packages" />
    <add key="repositoryPath" value="/home/abc/scratch/packages" />
  </config>
</configuration>

并通过以下命令验证了配置生效:

$ dotnet nuget locals all --list
http-cache: /home/abc/.local/share/NuGet/http-cache
global-packages: /home/abc/scratch/packages
temp: /tmp/NuGetScratchabc
plugins-cache: /home/abc/.local/share/NuGet/plugin-cache

你已通过wget手动下载了Newtonsoft.Json 13.0.3的包:

wget https://www.nuget.org/api/v2/package/Newtonsoft.Json/13.0.3

以下是将该包放置到指定目录并让dotnet识别的具体操作:

1. 重命名下载的压缩包

wget下载的文件默认名为13.0.3,需要改为NuGet标准包名格式:{包名}.{版本号}.nupkg,执行命令:

mv 13.0.3 Newtonsoft.Json.13.0.3.nupkg

2. 创建符合NuGet要求的目录结构

NuGet全局包目录要求严格的层级:{包名}/{版本号}/,在指定的packages目录下创建对应层级:

mkdir -p /home/abc/scratch/packages/Newtonsoft.Json/13.0.3

3. 解压包到目标目录

将重命名后的nupkg包解压到刚才创建的目录中:

unzip Newtonsoft.Json.13.0.3.nupkg -d /home/abc/scratch/packages/Newtonsoft.Json/13.0.3

4. 验证与项目引用

  • 检查目录结构:确保/home/abc/scratch/packages/Newtonsoft.Json/13.0.3下存在lib文件夹、Newtonsoft.Json.nuspec等核心文件
  • 如果项目尚未引用该包,手动编辑项目的.csproj文件添加引用:
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  • 执行dotnet restore命令,dotnet会自动从指定的全局包目录识别并加载该包

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 12:33:24