通过 dotnet CLI 更改 NuGet 包下载的默认位置

Changing default location of NuGet package download by dotnet CLI

对于 VS2019 中的 C# 控制台应用程序,我从 .NET CLI(Developer PowerShell)发出了以下命令:-

 dotnet add package <PackageName> --version <Version>

然后我从对象浏览器中发现程序包程序集 (.dll) 已被复制到我以 C:\Users.nuget\packages 开头的本地路径中。但是如果我看到我的项目定义(.csproj 文件),我只会看到包名称而不是路径:-

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="<PackageName>" Version="<Version>" />
  </ItemGroup>

</Project>

Visual Studio(或 .dotnet CLI)中决定应将 NuGet 包下载到哪个本地路径的设置在哪里?

这是全局 NuGet 缓存,它是可配置的(根据下面引用的文档),但你的是默认位置

https://www.github.com/NuGet/docs.microsoft.com-nuget/tree/main/docs%2Fconsume-packages%2Fmanaging-the-global-packages-and-cache-folders.md

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder. When using the packages.config, packages are installed to the global-packages folder, then copied into the project's packages folder.

Windows: %userprofile%.nuget\packages

Mac/Linux: ~/.nuget/packages

Override using the NUGET_PACKAGES environment variable, the globalPackagesFolder or repositoryPath configuration settings (when using PackageReference and packages.config, respectively), or the RestorePackagesPath MSBuild property (MSBuild only). The environment variable takes precedence over the configuration setting.