首页 > 解决方案 > Nuget 包未在 Visual Studio 中更新

问题描述

我正在创建一个 nuget 包,其中包含一些 dll。在这个包的第一次迭代之后,我的团队负责人要求我添加另一个 dll。我将它添加到 nuspec 文件中,从服务器中删除旧包,然后推送更新的包。我进入服务器并验证新添加的 dll 是否存在于 nuget 包中(即我解压缩 nuget 包并检查它的内容)。

到目前为止,一切看起来都很好。现在,我将新创建的包安装到一个测试项目中,然后清理并构建。当我检查 bin 文件夹时,它没有新添加的 dll。它仍然是与第一个包迭代相同的 dll 集,但在 nuget 服务器上它具有所有更新的 dll。

我已经清除了 nuget 缓存,删除了旧包并重新应用了更改,然后重新启动了 Visual Studio,但都没有成功。

我相信根本原因是版本号没有随着每次迭代而增加,因为我的团队负责人设定了要求(这对包本身来说是合乎逻辑的)。例如,当我更新 Package-v1 时,下一次更新仍将是 Package-v1。

我能做些什么来强制 Visual Studio 从服务器获取最新版本?另外,如果您知道,我想知道为什么会发生这种情况。

标签: c#visual-studionugetpackagepackage-managers

解决方案


What can I do to force visual studio to grab the latest version from the server? Also, I'd like to know why this is happening if you know.

The reason for this issue is that nuget always use the nuget cache or global-packages folders first to avoid downloading packages that already exist on the computer, improving the performance of install, update, and restore operations.

So, to resolve this issue, we should find out the nuget cache and delete it. It depends on the nuget package management type and repositoryPath/globalPackagesFolder settings in the nuget.config file.

If you nuget package management type is packages.config:

The default packages cache is in the \packages folder in the solution folder, you can check that package in the \packages folder. If not, check if you have any nuget.config with setting:

If yes, the packages cache will be saved on the new folder YourCustomFolder, delete that package from that folder.

If you nuget package management type is packagereference:

The default packages cache is in the global packages folder:

C:\Users\<UserName>\.nuget\packages

you can delete package in that folder, if you can not find the package from that global Packages Folder, check if you have any nuget.config with setting:

<add key="globalPackagesFolder" value="YourCustomFolder" />

If yes, delete package from the new folder.

Hope this helps.


推荐阅读