NuGet is a free, open source package management development tool for THE.NET platform.

Example Modify the global package management directory

To install packages through NuGet, NuGet first downloads the packages to a unified directory. The default path is C:\Users\ username \.nuget\packages

If too many packages are downloaded, disk C space is occupied. We can modify the configuration to specify a custom directory.

Search the NuGet.Config file, the default location is: C:\Users\ Username \AppData\Roaming\NuGet, add the following configuration under the root node:

<config>
  <add key="globalPackagesFolder" value="D:\packages" />
</config>
Copy the code

If NuGet.Config does not exist, you can create a new NuGet.Config in C: Program Files (x86)\NuGet\Config. . The folder Microsoft VisualStudio. Offline. The content of the config file is copied to the new NuGet. Config, then add the node.

Modify the package path in the project

When installing a package, NuGet searches the global package management directory first. If the package to be installed already exists, NuGet does not download it. If the package does not exist, NuGet downloads the package to the local global directory first.

Then copy the package files from the global package management directory into the Packages folder under the current project and add the corresponding DLLS to the project reference. (If you find a package in the global packages management directory, create a new text file in it, and then install the package in your project using NuGet, you will find that the new text file is copied to the corresponding package in the project packages directory.)

If you have packages under each project, you can end up with a lot of duplicate package files on your hard drive, which can be very frustrating. Projects can be configured to reference package files in the same directory.

For example, if your projects are in the D: SRC directory and you want to put all the package files in the D: SRC \packages directory, the directory structure is as follows:

D:\src
 |-- Soluation A
 |-- Soluation B
 |-- Soluation C
 |-- packages
Copy the code

Create a new NuGet. Config file in the D:\ SRC directory and add the following:

<?xml version="1.0" encoding="utf-8"? >
<configuration>
  <solution>
    <! -- Default does not commit packages to source control
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <config>
    <! -- Specify the default packages directory for this directory -->
    <add key="repositorypath" value="D:\src\packages" />
  </config>
  <packageRestore>
    <! -- Packages restore enabled by default -->
    <add key="enabled" value="True" />
  </packageRestore>
</configuration>
Copy the code

If the subdirectory also contains the NuGet. Config file, NuGet automatically merges the subdirectory configuration with the upper directory configuration. If the same configuration exists, The configuration in the subdirectory takes precedence.

Reference article:

Beginor. Making. IO / 2013/03/31 /…