How to manage the global packages, cache, temp folders in NuGet (2024)

  • Article

Whenever you install, update, or restore a package, NuGet manages packages and package information in several folders outside of your project structure:

NameDescription and Location (per user)
global-packagesThe 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.
http-cacheThe Visual Studio Package Manager (NuGet 3.x+) and the dotnet tool store copies of downloaded packages in this cache (saved as .dat files), organized into subfolders for each package source. Packages are not expanded, and the cache has an expiration time of 30 minutes.
  • Windows: %localappdata%\NuGet\v3-cache
  • Mac/Linux: ~/.local/share/NuGet/v3-cache
  • Override using the NUGET_HTTP_CACHE_PATH environment variable.
tempA folder where NuGet stores temporary files during its various operations.
  • Windows: %temp%\NuGetScratch
  • Mac: /tmp/NuGetScratch
  • Linux: /tmp/NuGetScratch<username>
  • Override using the NUGET_SCRATCH environment variable.
  • plugins-cache 4.8+A folder where NuGet stores the results from the operation claims request.
    • Windows: %localappdata%\NuGet\plugins-cache
    • Mac/Linux: ~/.local/share/NuGet/plugins-cache
    • Override using the NUGET_PLUGINS_CACHE_PATH environment variable.

    Note

    NuGet 3.5 and earlier uses packages-cache instead of the http-cache, which is located in %localappdata%\NuGet\Cache.

    By using the cache and global-packages folders, NuGet generally avoids downloading packages that already exist on the computer, improving the performance of install, update, and restore operations. When using PackageReference, the global-packages folder also avoids keeping downloaded packages inside project folders, where they might be inadvertently added to source control, and reduces NuGet's overall impact on computer storage.

    When asked to retrieve a package, NuGet first looks in the global-packages folder. If the exact version of package is not there, then NuGet checks all non-HTTP package sources. If the package is still not found, NuGet looks for the package in the http-cache unless you specify --no-http-cache with dotnet.exe commands or -NoHttpCache with nuget.exe commands. If the package is not in the cache, or the cache isn't used, NuGet then retrieves the package over HTTP .

    For more information, see What happens when a package is installed?.

    Viewing folder locations

    You can view locations using the nuget locals command:

    # Display locals for all folders: global-packages, http cache, temp and plugins cachenuget locals all -list

    Typical output (Windows; "user1" is the current username):

    http-cache: C:\Users\user1\AppData\Local\NuGet\v3-cacheglobal-packages: C:\Users\user1\.nuget\packages\temp: C:\Users\user1\AppData\Local\Temp\NuGetScratchplugins-cache: C:\Users\user1\AppData\Local\NuGet\plugins-cache

    (package-cache is used in NuGet 2.x and appears with NuGet 3.5 and earlier.)

    You can also view folder locations using the dotnet nuget locals command:

    dotnet nuget locals all --list

    Typical output (Mac; "user1" is the current username):

    info : http-cache: /home/user1/.local/share/NuGet/v3-cacheinfo : global-packages: /home/user1/.nuget/packages/info : temp: /tmp/NuGetScratchinfo : plugins-cache: /home/user1/.local/share/NuGet/plugins-cache

    Typical output (Linux; "user1" is the current username):

    info : http-cache: /home/user1/.local/share/NuGet/v3-cacheinfo : global-packages: /home/user1/.nuget/packages/info : temp: /tmp/NuGetScratchuser1info : plugins-cache: /home/user1/.local/share/NuGet/plugins-cache

    To display the location of a single folder, use http-cache, global-packages, temp, or plugins-cache instead of all.

    Clearing local folders

    If you encounter package installation problems or otherwise want to ensure that you're installing packages from a remote gallery, use the locals --clear option (dotnet.exe) or locals -clear (nuget.exe), specifying the folder to clear, or all to clear all folders:

    # Clear the 3.x+ cache (use either command)dotnet nuget locals http-cache --clearnuget locals http-cache -clear# Clear the 2.x cache (NuGet CLI 3.5 and earlier only)nuget locals packages-cache -clear# Clear the global packages folder (use either command)dotnet nuget locals global-packages --clearnuget locals global-packages -clear# Clear the temporary cache (use either command)dotnet nuget locals temp --clearnuget locals temp -clear# Clear the plugins cache (use either command)dotnet nuget locals plugins-cache --clearnuget locals plugins-cache -clear# Clear all caches (use either command)dotnet nuget locals all --clearnuget locals all -clear

    Any packages used by projects that are currently open in Visual Studio are not cleared from the global-packages folder.

    Starting in Visual Studio 2017, use the Tools > NuGet Package Manager > Package Manager Settings menu command, then select Clear All NuGet Cache(s). Managing the cache isn't presently available through the Package Manager Console. In Visual Studio 2015, use the CLI commands instead.

    How to manage the global packages, cache, temp folders in NuGet (1)

    Troubleshooting errors

    The following errors can occur when using nuget locals or dotnet nuget locals:

    • Error: The process cannot access the file <package> because it is being used by another process or Clearing local resources failed: Unable to delete one or more files

      One or more files in the folder are in use by another process; for example, a Visual Studio project is open that refers to packages in the global-packages folder. Close those processes and try again.

    • Error: Access to the path <path> is denied or The directory is not empty

      You don't have permission to delete files in the cache. Change the folder permissions, if possible, and try again. Otherwise, contact your system administrator.

    • Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

      Shorten the folder names and try again.

    As an expert in NuGet package management, I bring extensive knowledge and hands-on experience with the intricacies of package installation, update, and restoration processes. My expertise is underscored by a deep understanding of NuGet's folder structure and how it manages packages on various operating systems.

    NuGet, a package manager for the Microsoft development platform, organizes packages and package information in distinct folders outside of the project structure. Let's delve into the key concepts discussed in the provided article:

    1. global-packages:

      • Description: NuGet installs downloaded packages in this folder, fully expanded into subfolders matching the package identifier and version.
      • Location:
        • Windows: %userprofile%\.nuget\packages
        • Mac/Linux: ~/.nuget/packages
      • Override Options:
        • NUGET_PACKAGES environment variable
        • globalPackagesFolder or repositoryPath configuration settings
        • RestorePackagesPath MSBuild property
    2. http-cache:

      • Description: Visual Studio Package Manager and the dotnet tool store downloaded packages (saved as .dat files) in this cache, organized by package source.
      • Location:
        • Windows: %localappdata%\NuGet\v3-cache
        • Mac/Linux: ~/.local/share/NuGet/v3-cache
      • Override Option:
        • NUGET_HTTP_CACHE_PATH environment variable
    3. temp:

      • Description: NuGet uses this folder for storing temporary files during various operations.
      • Location:
        • Windows: %temp%\NuGetScratch
        • Mac/Linux: /tmp/NuGetScratch<username>
      • Override Option:
        • NUGET_SCRATCH environment variable
    4. plugins-cache (4.8+):

      • Description: Results from the operation claims request are stored in this folder.
      • Location:
        • Windows: %localappdata%\NuGet\plugins-cache
        • Mac/Linux: ~/.local/share/NuGet/plugins-cache
      • Override Option:
        • NUGET_PLUGINS_CACHE_PATH environment variable
    5. Package Retrieval Process:

      • NuGet first looks in the global-packages folder.
      • If the package is not found, NuGet checks all non-HTTP package sources.
      • If still not found, NuGet looks for the package in the http-cache.
      • If the package is not in the cache, or the cache isn't used, NuGet retrieves the package over HTTP.
    6. Viewing Folder Locations:

      • Use nuget locals all -list or dotnet nuget locals all --list to display the locations of global-packages, http-cache, temp, and plugins-cache.
    7. Clearing Local Folders:

      • Use nuget locals <folder> --clear or dotnet nuget locals <folder> --clear to clear specific folders or all to clear all folders.
    8. Troubleshooting Errors:

      • Errors related to file access, permissions, or path length may occur when using nuget locals or dotnet nuget locals.

    By applying this knowledge, developers can efficiently manage NuGet packages, troubleshoot issues, and optimize performance by clearing cache folders as needed.

    How to manage the global packages, cache, temp folders in NuGet (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Annamae Dooley

    Last Updated:

    Views: 5978

    Rating: 4.4 / 5 (65 voted)

    Reviews: 88% of readers found this page helpful

    Author information

    Name: Annamae Dooley

    Birthday: 2001-07-26

    Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

    Phone: +9316045904039

    Job: Future Coordinator

    Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

    Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.