如何使用命令行清除NuGet包缓存?

本文翻译自:How to clear NuGet package cache using command line?

I can clear my dev computer's NuGet package cache using VS Tools/Options/NuGet Package Manager/General: [Clear Package Cache] button. 我可以使用VS Tools / Options / NuGet Package Manager / General:[Clear Package Cache]按钮清除我的开发计算机的NuGet包缓存。

I would like to do this in command line. 我想在命令行中执行此操作。 Unfortunately I can not find related command line switch for nuget.exe. 不幸的是我找不到nuget.exe的相关命令行开关。

Did I miss something? 我错过了什么?


#1楼

参考:https://stackoom.com/question/25n9p/如何使用命令行清除NuGet包缓存


#2楼

The nuget.exe utility doesn't have this feature, but seeing that the NuGet Cache is simply a folder on your computer, you can delete the files manually. nuget.exe实用程序没有此功能,但是看到NuGet Cache只是计算机上的文件夹,您可以手动删除这些文件。 Just add this to your batch file. 只需将其添加到批处理文件中即可。

del %LOCALAPPDATA%\NuGet\Cache\*.nupkg /q

#3楼

First, download the NuGet command line tool from here . 首先,从这里下载NuGet命令行工具。

Next, open a command prompt and cd to the directory to which nuget.exe was downloaded. 接下来,打开命令提示符并cd到下载nuget.exe的目录。

You can list the local caches with this command: 您可以使用以下命令列出本地缓存:

nuget locals all -list

You can clear all caches with this command: 您可以使用此命令清除所有缓存:

nuget locals all -clear

Reference: https://docs.nuget.org/consume/command-line-reference 参考: https : //docs.nuget.org/consume/command-line-reference


#4楼

This adds to rmoore's answer. 这增加了rmoore的答案。

Download and install the NuGet command line tool. 下载并安装NuGet命令行工具。

  • from Chocolaty -> https://chocolatey.org/packages/NuGet.CommandLine 来自Chocolaty - > https://chocolatey.org/packages/NuGet.CommandLine
  • from NuGet.org -> https://www.nuget.org/ 来自NuGet.org - > https://www.nuget.org/

List all of our locals. 列出我们所有的当地人。

$ nuget locals all -list
http-cache: C:\Users\MyUser\AppData\Local\NuGet\v3-cache
packages-cache: C:\Users\MyUser\AppData\Local\NuGet\Cache
global-packages: C:\Users\MyUser\.nuget\packages\

We can now delete these manually or as rmoore suggests, use nuget locals all -clear . 我们现在可以手动删除它们,或者如rmoore所建议的那样,使用nuget locals all -clear


#5楼

You can use powershell to (same as me). 你可以使用powershell(和我一样)。

For example: 例如:

rm $env:LOCALAPPDATA\NuGet\Cache\*.nupkg

or 'quiet' mode (without error messages): 或'安静'模式(没有错误消息):

rm $env:LOCALAPPDATA\NuGet\Cache\*.nupkg 2> $null

#6楼

If you need to clear Nuget cache for your build server/agent you can find cache for Nuget packages here: 如果您需要为构建服务器/代理清除Nuget缓存,可以在此处找到Nuget包的缓存:

%windir%/ServiceProfiles/[account under build service runs]\\AppData\\Local\\NuGet\\Cache

Example: C:\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Local\\NuGet\\Cache 示例:C:\\ Windows \\ ServiceProfiles \\ NetworkService \\ AppData \\ Local \\ NuGet \\ Cache

你可能感兴趣的:(如何使用命令行清除NuGet包缓存?)