Is there a way to automatically update an installe

2019-07-10 07:17发布

问题:

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.