Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
525 views
in Technique[技术] by (71.8m points)

.net core - Change NuGet package folders used by Visual Studio 2017

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

NuGet CLI gets the list of used cache folders:

nuget locals all -list

Response:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Cache locations

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

NuGet is now fully integrated into MSBuild:

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+ uses at least two global package locations:

  • User-specific: %userprofile%.nugetpackages
  • Machine-wide: %ProgramFiles(x86)%Microsoft SDKsNuGetPackages"

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

nuget locals all -list

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

Options -> NuGet Package Manager -> Package Sources

Configuration files

NuGet.config files are located here:

  • User-specific: %APPDATA%NuGet
  • Machine-wide: %ProgramFiles(x86)%NuGetConfig

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

  • project
  • solution
  • user
  • machine

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

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...