且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法在 Visual Studio 中自动更新已安装的 NuGet 包?

更新时间:2023-11-19 21:03:34

NuGet 包还原功能特意仅适用于一个特定版本.同一个版本号不同的包,如果缺少版本号较低的包,将不会使用.

The NuGet package restore feature intentionally only works for one specific version. The same package with a different version number will not be used if the package with a lower version is missing.

示例 1

  • packages.config 引用 1.0.0.0
  • 包源包含 1.0.0.0 和 1.0.0.1
  • 1.0.0.0是会自动恢复的版本
  • packages.config references 1.0.0.0
  • package source contains 1.0.0.0 and 1.0.0.1
  • 1.0.0.0 is the version that will automatically be restored

示例 2

  • packages.config 引用 1.0.0.0
  • 包源仅包含 1.0.0.1
  • 不会执行自动恢复,项目不会构建

这种行为是有道理的,否则就无法控制您实际构建的内容.想象一下,在您构建将要发布的版本之前,有人用更新版本的包更新了包源...

This behaviour makes sense as otherwise there is no way to control what you are actually building. Imagine someone updates the package source with a newer version of a package just before you build a release that will get shipped...