How to NuGet jQuery 1, the Right Way

The jQuery team made a decision in 2013 to split the library into two versions, one supporting IE6 upwards and the other IE9, these were labeled jQuery 1 and 2 respectively. This resulted in two key NuGet packages on the gallery:

If you need IE6, 7 or 8 support then the obvious choice is the jQuery1 package, and this will work perfectly fine until you install a NuGet package with a jQuery dependency. When installing this package  jQuery will automatically be installed from the gallery, ignoring the fact jQuery1 is already installed, and leaving you with two versions of the same library. This was caused because there is absolutely no correlation between the two package, and they are seen as completely separate libraries.

After some research I discover that you can install a version of a package and specify the acceptable versions in the package.config file. The first step is to install the requires version via the package management console, jQuery example below:

PM> Install-Package jQuery -Version 1.11.0

Once installed open the package.config file (located at the root if your project) and identify the jQuery details. The attribute ‘allowedVersions’ can be added here to dictate the acceptable version (more details can be found in the NuGet documentation).

<package id=”jQuery” version=”1.11.0″ targetFramework=”net451″ allowedVersions=”(,2.0.0)” />

The above example allows for all jQuery versions under 2.0.0. This means packages that have a jQuery dependency can be installed without an unwanted second jQuery package, NuGet will also only identify updates to jQuery with a version under 2.0.0.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: