Is there a way to automatically update an installed NuGet package in Visual Studio?

浪子不回头ぞ 提交于 2019-12-24 05:15:35

问题


As the title says, I'd like to know if there is a way to automatically update an installed NuGet package as soon as a new version becomes available in the package source.

The use case is a package that applies certain company policies (code analysis, signing, ...) to our projects, and as soon as this package is updated, I'd like to be able to configure an automatic update for this package.

I do know that there is a package restore feature for NuGet which will automatically download the missing packages when the project is built, but does this download a specific version or the most recent package with a matching name?


回答1:


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.

Example 1

  • 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

Example 2

  • packages.config references 1.0.0.0
  • package source contains only 1.0.0.1
  • no automatic restore will be performed, the project won't build

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...




回答2:


Although coming late to the party, I would like to add, that updating NuGet packages may be possible with PackageReference.

See https://docs.microsoft.com/de-de/nuget/reference/package-versioning.



来源:https://stackoverflow.com/questions/31850236/is-there-a-way-to-automatically-update-an-installed-nuget-package-in-visual-stud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!