visual-studionugetnuget-packagecsprojpackagereference

PackageReference version is ignored


In our project we're creating different NuGet packages (using suffixes) for different branches. In the .csproj file I'm trying to specify the specific version of a package that should be used. Package names can be 1.2.3, 1.2.3-rc001, or 1.2.3-pr001.

First issue: I tested using
<PackageReference Include="Package.Name" Version="[1.2.3,1.2.6)" /> where there was no 1.2.3. My understanding is it should use the next available version, but now it simply says the selected package is 1.2.3, with "Not available in this source". Updating NuGets also ignores this and simply updates to the latest release, 1.2.10. After that it overwrites the Version in .csproj, so the specified bounds are lost.

Second issue, that falls in with the first, is to specify to only use -pr* or -rc* versions. 1.2.*-pr* is not a valid option, so maybe our numbering scheme needs changing.


Solution

  • First issue: I tested using where there was no 1.2.3. My understanding is it should use the next available version, but now it simply says the selected package is 1.2.3, with "Not available in this source".

    Actually, when you set different versions of a nuget package by floating versions(in your situation, 1.2.3<=version<1.2.6), NuGet chooses the package that's closest to the application and ignore the others. So it will choose 1.2.3 regardless of whether it exists in your current nuget caches.See this document.

    So PackageReference will not reference the package based on the closest available version in your current cache and choose the newest version not matter whether it exits under your local machine.

    Second issue, that falls in with the first, is to specify to only use -pr* or -rc* versions. 1.2.-pr is not a valid option, so maybe our numbering scheme needs changing.

    At the moment, prerelease versions cannot be used together with floating versions.It means that you cannot use any pre-release characters with floating versions . So -pr* and -rc* are illegal including 1.2.*-pr*.

    During use, no characters about the pre-release version can appear.

    Instead, you can use

    1.2.*-*
    

    Besides, the 1.2.*-beta1 is also illegal. Though it shows a version under Dependencies UI, you can not find it under Nuget Package Manager-->Installed which means that the package is missing and the project has lost it.

    In addition, there is a similar issue which you can refer to.