NuGet 如何决定是否使用本地包缓存? [英] How does NuGet decide whether to use local package cache or not?

查看:88
本文介绍了NuGet 如何决定是否使用本地包缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我在安装包时遇到了 NuGet 的奇怪行为.

Today I've faced with a strange behavior of NuGet when installing a package.

简要说明:作为我的构建脚本的结果,有一个 NuGet 包.我不会每次都更改版本,因此每次构建都会生成 MyPackage.1.0.0.nupkg.作为构建的最后一步,我将包推送到部署在本地网络内的 NuGet 服务器.

A brief description: as a result of my build script there's a NuGet package. I don't change the version each time, so each and every build produces MyPackage.1.0.0.nupkg. As the final step of the build, I push the package to the NuGet server deployed inside the local network.

现在,在另一台机器上,我运行 nuget install MyPackage -Source http://myserver/nuget,这显然安装了 NuGet 包.

Now, on a different machine, I run nuget install MyPackage -Source http://myserver/nuget, which obviously installs the NuGet package.

当我推送 MyPackage 的另一个更新时,问题就出现了 - 仍然是 1.0.0 版本.当我尝试在客户端计算机上重新安装它时,我得到了该软件包的先前版本.

The problem comes into play when I push another update of MyPackage - still of version 1.0.0. When I try to re-install it on client machine, I get the previous version of the package.

我发现应该归咎于本地缓存:如果安装了包,它会进入本地缓存,下次安装相同版本的包时,它会从缓存中取出.够公平!

I found out it is the local cache to be blamed: if the package was installed, it gets into the local cache and the next time the package of the same version is installed, it is taken from cache. Fair enough!

但是,另一方面,nuget install 命令有一个 -NoCache 选项,我希望它忽略本地缓存.

But, on the other hand, there's a -NoCache option of the nuget install command, and I expect it to ignore the local cache.

然而,事实并非如此.我第一次使用 -NoCache 运行它时,它会更新缓存并安装真正的最新版本.但是,下次仍然从缓存中取出包,即使使用 -NoCache 选项.

However, this is not true. The first time I run it with -NoCache, it updates the cache and installs the true latest version. But, the next time the package is still taken from cache, even with -NoCache option.

这是预期的吗?是不是因为版本没改?

Is it expected? Is it because of the version not being changed?

以防万一:所有 NuGet 操作都是通过 NuGet.exe 和 PowerShell 会话完成的.

Just in case: all NuGet operations are done with NuGet.exe and from PowerShell session.

UPDATE:我观察到奇怪的行为,我只能通过缓存过期来解释.当包被缓存时,对 nuget install 的所有后续调用从缓存中拉出包,直到一段时间过去.我没有注意到确切的时间,但肯定是一个多小时.之后,nuget install更新缓存中的包,情况变得一样...

UPDATE: I observe strange behavior I can only explain by cache expiration. When the package is cached, all subsequent calls to nuget install pull the package from cache, until some time passes. I didn't notice the exact period, but it's definitely more than an hour. After this, nuget install updates the package in the cache, and the situation becomes the same...

推荐答案

Yan,

我推送了 MyPackage 的另一个更新 - 仍然是 1.0.0 版本.

I push another update of MyPackage - still of version 1.0.0.

您不应该推送多个具有特定版本的包:包应该是不可变的.如果您更改了包中的某些内容,请增加内部版本号 a.b.C 并推送包的新版本.

You should not be pushing more than one package with a particular version: packages should be immutable. If you've changed something in the package, increment the build number a.b.C and push a new version of the package.

您遇到的行为是 NuGet 的副作用,期望能够基本上无限期地缓存给定的包版本.

The behaviour you experience is a side effect of NuGet expecting to be able to cache a given package version essentially indefinitely.

这篇关于NuGet 如何决定是否使用本地包缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆