我可以清除我的开发计算机的NuGet包缓存使用Visual Studio菜单工具→选项→NuGet包管理器→通用:清除包缓存按钮。

我希望在命令行上执行此操作。不幸的是,我找不到nuget.exe的相关命令行开关。

我错过什么了吗?


NuGet .exe工具没有这个功能,但看到NuGet缓存只是你电脑上的一个文件夹,你可以手动删除文件。只需添加到你的批处理文件:

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

首先,从这里下载NuGet命令行工具。

接下来,打开命令提示符并cd到nuget.exe下载到的目录。

你可以用这个命令列出本地缓存:

nuget locals all -list

你可以用这个命令清除所有的缓存:

nuget locals all -clear

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

这增加了rm8x的答案。

下载并安装NuGet命令行工具。

来自Chocolatey→https://chocolatey.org/packages/NuGet.CommandLine 从NuGet.org→https://www.nuget.org/

列出我们所有的局部变量:

$ 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\

我们现在可以手动删除这些,或者像rm8x建议的那样,使用nuget locals all -clear。

你也可以使用PowerShell(和我一样)。

例如:

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

或“安静”模式(没有错误消息):

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

如果你需要为你的构建服务器/代理清除NuGet缓存,你可以在这里找到NuGet包的缓存:

%windir%/ServiceProfiles/[在构建服务下运行的帐户]\AppData\Local\NuGet\Cache

例子:

C:\Windows\ServiceProfiles\NetworkService\AppData\Local\NuGet\Cache

注意,dnx有一个不同的缓存来提供HTTP结果:

Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16231
   CACHE https://www.nuget.org/api/v2/
   CACHE http://192.168.148.21/api/odata/

你能澄清吗

dnu clear-http-cache

现在我们只需要找出新的dotnet CLI工具上的命令是什么。

...就是这样:

dotnet restore --no-cache

对我来说,我必须在这里:

%userprofile%\.nuget\packages

在Visual Studio 2022中,进入菜单“工具→NuGet包管理器→包管理器设置”。你可能会发现一个按钮,清除所有NuGet存储:

这些步骤在以前版本的Visual Studio中也类似。

如果你正在使用。net Core,你可以用这个命令清除缓存,这应该在。net Core tools 1.0中起作用:

dotnet nuget locals all --clear

Dotnet nuget本地安全

如果你使用的是。net Core。

我在这里结束,因为我试图弄清楚如何从缓存中删除特定的nuget包。上面的答案讨论了使用nuget locals all -clear删除所有本地包。

如果有人对清除特定的包感兴趣,我将分享我的发现:

You can't currently clear a specific package using the nuget or dotnet cli. There is a github issue open to fix this: https://github.com/NuGet/Home/issues/5713 For now, you have to resort to filesystem commands (as some of the answers above mention) to delete the specific package. For mac/linux, it was rm -rf ~/.nuget/packages/<package-name> What I actually needed was a way to delete the cache of a specific package that I was about to re-publish to a local nuget repository (using a fixed version number to make local development easier). I accomplished this by adding the following to the .csproj file of the nuget-packaged library:

    <Project>
      <Target Name="DeleteLocalCache" BeforeTargets="Pack">
        <RemoveDir Directories="$(NugetPackageRoot)/$(PackageId.ToLower())/1.0.0-local"/>
      </Target>
    </Project>

对于那些在RHEL7上安装nuget的人(例如,从EPEL存储库中),使用sudo yum install nuget,这里是本地缓存的位置:

~/.local/share/NuGet/Cache

我看到我的nuget在这个文件夹(在构建服务器上):c:\Windows\System32\config\systemprofile.nuget\packages\