简体   繁体   中英

Visual Studio 2019 Nuget cannot find a package

My packages.config has this entry:

<package id="xxxxxx" version="3.0.0" allowedVersions="[3.0,3.3)" targetFramework="net452">

Now there is no package xxxxxxx at version 3.0.0 (there might have been, once upon a time), but I am allowing anything between 3.0 and 3.3. I do have a package at 3.1.0, and I expected that nuget would find that one and pick it up, but I get the error

Unable to find version '3.0.0' of package xxxxxxxx

Questions:

  1. Why does nuget not say, "oh I can't find 3.0.0 but I'm allowed to use anything from 3.0 to 3.3 and I have 3.1.0. I'll use that!"
  2. What is the correct config to use to make it pick up the highest available version in the allowed range?

In packages.config , every dependency is listed with an exact version attribute that's used when restoring packages. The allowedVersions attribute is used only during update operations to constrain the versions to which the package might be updated.

Source: https://docs.microsoft.com/en-us/nuget/concepts/package-versioning#references-in-project-files-packagereference

If you want to use ranges in your project, you will have to switch to References in project files (PackageReference), but keep in mind:

NuGet 2.8.x and earlier chooses the latest available package version when resolving a dependency, whereas NuGet 3.x and later chooses the lowest package version.

Option to always resolve to highest version was proposed and rejected: https://github.com/NuGet/Home/issues/1192

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM