更改 Visual Studio 2017 使用的 NuGet 包文件夹 [英] Change NuGet package folders used by Visual Studio 2017

查看:40
本文介绍了更改 Visual Studio 2017 使用的 NuGet 包文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何基于 csprojproject.json 的 .NET Core 项目中都没有更多的 packages 解决方案文件夹.

There is no more packages solution folder in any csproj or project.json-based .NET Core project.

NuGet CLI 获取使用的缓存文件夹列表:

NuGet CLI gets the list of used cache folders:

nuget locals all -list

回复:

http-cache: C:Users<foo>AppDataLocalNuGetv3-cache
global-packages:  C:Users<foo>.nugetpackages
temp: C:Users<foo>AppDataLocalTempNuGetScratch

如何更改或覆盖这些位置?

How to change or override these locations?

推荐答案

缓存位置

.NET Core 和 Visual Studio 2017 不再存在解决方案本地包文件夹.

Cache locations

Solution-local packages folders are no longer exist for .NET Core and Visual Studio 2017.

NuGet 现在已完全集成到 MSBuild 中:

不再使用解决方案本地包文件夹 - 现在包针对 %userdata%.nuget 处的用户缓存进行解析,而不是解决方案特定的包文件夹.这使得 PackageReference 执行通过使用共享文件夹更快并消耗更少的磁盘空间工作站上的软件包.

Solution-local packages folders are no longer used – Packages are now resolved against the user’s cache at %userdata%.nuget, rather than a solution specific packages folder. This makes PackageReference perform faster and consume less disk space by using a shared folder of packages on your workstation.

NuGet 4.0+ 使用至少两个全局包位置:

NuGet 4.0+ uses at least two global package locations:

  • 特定于用户:%userprofile%.nugetpackages
  • 机器范围:%ProgramFiles(x86)%Microsoft SDKsNuGetPackages"

您可以使用以下控制台命令列出所有用户特定的文件夹:

You can list all user-specific folders using the following console command:

nuget locals all -list

请注意,此处未列出机器范围的文件夹.但是,它是在 Visual Studio 设置中定义的:

Notice that the machine-wide folder isn't listed there. However, it is defined at Visual Studio settings:

Options -> NuGet Package Manager -> Package Sources

配置文件

NuGet.config 文件 位于此处:

  • 特定于用户:%APPDATA%NuGet
  • 机器范围:%ProgramFiles(x86)%NuGetConfig

可以在多个级别更改和覆盖 NuGet 设置:

It is possible to change and override NuGet settings at many levels:

  • 项目
  • 解决方案
  • 用户
  • 机器

还有更多!在此处阅读有关 NuGet.config 分层优先级排序的更多信息:如何应用设置.

And even more! Read more about NuGet.config hierarchical priority ordering here: How settings are applied.

例如,globalPackagesFolder 参数更改包缓存位置.看看这个 NuGet.config 示例:

For example, globalPackagesFolder parameter changes a package cache location. Look at this NuGet.config example:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <clear />
    <add key="globalPackagesFolder" value="c:packages" />
  </config>
</configuration>

这篇关于更改 Visual Studio 2017 使用的 NuGet 包文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆