Share via


How to use allowedVersions tag in packages.config to set the version constraint

Question

Monday, May 22, 2017 11:51 AM

Reference Link -

https://docs.microsoft.com/en-us/nuget/schema/packages-config

**Content referred - **

allowedVersions No A range of allowed versions for this package in case the specific value in version cannot be found.

I have used this allowedVersion tag in my packages.config file for this below NuGet

<packages>
  <package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" allowedVersions="[6.0.0, 10.0.0)" />
</packages>

But am unable to update the version to 10.0 versions while updating from my VS 2017/VS 2017 in package manager console and CLI.  

Could anyone update the solution about this issue.  

- Abbas K

All replies (6)

Wednesday, May 31, 2017 4:02 AM ✅Answered | 1 vote

@Visual Studio Extensions, Not sure how can you get the 6.0.0 version of the Newtonsoft.Json package, there is no package on that version on the NuGet Package Manager UI and NuGet.org, just have the version from 5.08 to 6.0.1:

In this case, NuGet will restore fail. To resolve this issue, you should make sure the package version in the config is correct, like 6.0.1 rather than 6.0.0:

<packages>
  <package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" allowedVersions="[6.0.1, 10.0.1]" />
</packages>

Hope this can help you.

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Tuesday, May 23, 2017 7:07 AM | 1 vote

Hi friend,

Thanks for posting here.

>>>***But am unable to update the version to 10.0 versions while updating from my VS 2017/VS 2017 in package manager console and CLI.  ***

That is because you have set the

allowedVersions="[6.0.0, 10.0.0)"

in your package.config file, the applied rule for this version range is: 6.0.0≤ x < 10.0.0, Mixed inclusive minimum and exclusive maximum version. For more detail rule, you can refer to Version ranges. So the version 10.0 will not be allowed to be installed.

Besides, the package of Newtonsoft.Json have the version 10.0.1 and 10.0.2:

So if you want to update the version to 10.0 and later, you can change the settings of the version constraint to:

<packages>
  <package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" allowedVersions="[6.0.1, 10.0.2]" />
</packages>

Hope this can help you.

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Thursday, May 25, 2017 1:27 PM

@Visual Studio Extensions, any update for the question? Does the answer resolve you queation? If yes, you can mark it as answer, so that other communities meet the same issue and can easy find the answer. If not, please let me know the latest status for this question. Thanks.

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Tuesday, May 30, 2017 9:20 AM

Hi,

Thanks for the update. Package restore failed with below case,

Update packages.config like below,

<package id="Newtonsoft.Json" version="6.0.0" targetFramework="net452" allowedVersions="[6.0.0, 10.0.1]" />

Then try to restore. Below error will be occurred. 



- Abbas K


Thursday, June 1, 2017 4:02 AM

Hi,

Thanks for the response.

Yes. If we provide the version that will be available in NuGet server this will works perfect. As per their previous user guide content"A range of allowed versions for this package in case the specific value in version cannot be found" from below link,  

https://docs.microsoft.com/en-us/nuget/schema/packages-config

I thought the allowedversion attribute used for package install/restore while particular version not found. Now they modified the content as

"A range of allowed versions for this package applied during package update (see Constraining upgrade versions. It does not affect what package is installed during an install or restore operation. See Dependency versions - version Ranges for syntax. The PackageManager UI also disables all versions outside the allowed range."

So, that attribute set the version constraint while package update only. No issues now.

- Abbas K


Thursday, June 1, 2017 5:15 AM

@Abbas K, thanks for your reply. Did the answer resolve your question? If yes, you can mark it answer, so it could help other community members who get the same issues and easy to find the answer.

If not, you can share your question here, and if you have other more question, you can submit a new post for free. Thanks.

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].