Specifying NuGet package version numbers in the Package.config file in your Visual Studio projects

Posted: (EET/GMT+2)

 

NuGet is Visual Studio's own package manager that works well from both the command-line and from within the Visual Studio IDE. Also, NuGet allows you to easily update packages during builds.

However, there are certain situations where you might wish to control which version of packages should be available, and/or automatically updated to your project. The Package.config file contains lines like this:

<package id="jQuery" version="2.0.2" targetFramework="net452" />

Here, the current version of the jQuery package is version 2.0.2, and it can be updated to any version that is available. You can also use so-called version ranges, which have their own specific syntax.

In addition to specifying the package version, you can also specify which are allowed version updates in your project. This is done using the "allowedVersion" property on the above XML line.

Here's the syntax in its most important parts; copied directly from the NuGet documentation:

Notation Applied rule Description
1.0 1.0 ≤ x Minimum version, inclusive
(1.0,) 1.0 <> Mininum version, exclusive
[1.0] x == 1.0 Exact version match
(,1.0] x ≤ 1.0 Maximum version, inclusive
(,1.0) x <> Maximum version, exclusive
[1.0,2.0] 1.0 ≤ x ≤ 2.0 Exact range, inclusive
(1.0,2.0) 1.0 < x < 2.0 Exact range, exclusive

Hope this helps!