86

Like most people, I'm using the jQuery Nuget package to keep up to date.

However, with the release of jQuery 2.0 I'm now prompted to upgrade jQuery 1.9.1 to 2.0. At this time I have enough visitors across my sites using 'ancient' versions of browsers that I'd rather stick with 1.9.x and jQuery Migrate.

Is there anyway to tell Nuget to stick with a particular version (1.9.x) when checking for updates of a package (jQuery or otherwise)?

I'm using the Visual Studio 2010/2012 extensions, but if I need to use the command line interface within VS to work around this issue, I certainly will.

Note: One thing in the back of my mind is that they messed up the update. Since jQuery 1.9.x and 2.0.x/2.x are fairly different, it seems they should have created a jQuery 2(.0.x|.x) package instead.

Of course then people who actually want to update to 2.x will have to know about it and switch which package they want installed. But given that it contains breaking changes, maybe that's better?

3
  • 2
    Since 1.10.x is out, I've updated the title to make it a bit more clear. May 26, 2013 at 19:04
  • 2
    Since they are keeping the single nuget package, would be nice if they just added both jQuery versions to it, so you'd have both 1.x and 2.x branches in a single nuget package and then could reference the one you wanted.
    – John
    Jun 19, 2013 at 12:05
  • @John - I ... really like that idea. It's not like the package actually updates any references to the particular version. The only thing I can think of is projects which may actually require 2.x or 1.x? But, it would be interesting on whether this would work. +1 Jun 28, 2013 at 21:53

4 Answers 4

117

In my opinion, this is a mistake on the package author's part. An update which removes support for several browsers should have been made into a separate version 2 nuget package and advertised accordingly, i.e. with significant disclaimers. The 1.9 library is not legacy and will receive further updates in the future. I've been in touch with the package author and will write more if I receive a reply.

In the interim, you can constrain the version of your package by using the following syntax in your packages.config:

<package id="jQuery" version="1.9.1" allowedVersions="[1.9.1]" />

There's more information on version constraints here:

http://docs.nuget.org/docs/reference/Versioning

After making the config change, an update should not upgrade your jQuery package to the 2.0 release. There have been issues in the past with the UI package manager not respecting the allowedVersions attribute (https://nuget.codeplex.com/workitem/1891), so you may have to use the command line if you encounter this problem.

However, none of this solves the problem of what happens when the 1.9 branch gets updated because the package feed will now be on the 2.0+ track. I assume you'll have to switch to a new nuget package specifically written to support the 'legacy' 1.x version, or copy the script in manually each time.

In any case, I'll update this when I learn more.

Edit:

The package author has stated that both the 1.x and 2.x paths will be supported in the future, i.e. the package feed will contain parallel versions instead of them being split. As far as I can see, the solution is to use a version constraint at the package config level to prevent an update to the 2.x version, e.g.:

<package id="jQuery" version="1.9.1" allowedVersions="[1.9.1,2)" />

(Specifying both min and max versions in allowedVersions should allow updating without risking a switch to the 2.x version. By the way, the right parenthesis looks strange, but is correct - it means 'less than version 2'.)

13
  • Dave, thanks for reaching out to the package author. I did post a comment on the jQuery 2.0 announcement blog post about this being a possible issue; for some reason I thought jQuery was maintained by jQuery, and it was jQuery Migrate that was handled on behalf of them. Should have dug further. +1 Apr 22, 2013 at 17:53
  • @JamesSkemp - Yep, it was your query on the announcement post that brought me here :) Thanks for raising the question - I would have been caught out myself if you brought attention to the issue. The whole situation is rather more convoluted than it needs to be really, but I hope the updated answer helps. If I come across an easier way to handle the versioning, I'll be sure to add further info.
    – Dave R.
    Apr 22, 2013 at 23:25
  • 2
    The NuGet UI has a bug that causes it to prompt to update to jQuery 2.0 even if you disallow the update in packages.config. It's ironic that jQuery 2.0 came out so close to NuGet 2.5. Version 2.5 has an Update All button, which would be great if it weren't for this bug. Apr 28, 2013 at 13:03
  • 2
    I've seen that there's now a jquery1 package on nuget, which only tracks the 1.x branch.
    – Chris J
    Sep 26, 2013 at 7:50
  • 1
    Only console update, not UI update is working for me (after allowedVersions added). UI doesnt allow selection of any projects when update is attempted Feb 3, 2014 at 21:45
19

how about to specify the version?

PM> Install-Package jQuery -Version 1.9.1

References: http://nuget.org/packages/jQuery/1.9.1

3
  • Related question I asked: stackoverflow.com/q/16126338/11912 In short, it works, but it's klunky. And a blind update breaks it. Apr 22, 2013 at 17:54
  • I've actually started using the console way more after the jQuery versioning snafu (I'll call it that). Not the best solution, but +1. Jun 28, 2013 at 21:54
  • +1 because if you already upgraded to 2.x by mistake and want to go back to 1.9 AND prevent upgrading to 2.x, you need to downgrade it manually like this before / after adding the restriction from the approved answer.
    – Pluc
    Nov 17, 2014 at 15:47
8

Nuget now has a jquery1 package that only tracks the 1.x branch, so you should be able to swap out the core jQuery package for this one.

3
  • Good find. While the page needs a bit of work to be more readable, I like the flexibility this allows to have multiple versions of jQuery available. Sep 26, 2013 at 19:41
  • Although that brings us back to John's comment on the question; it would be nice if there was a package that just had both 1.x and 2.x, with the current version of each, in it. Sep 26, 2013 at 19:42
  • 2
    But if you have other libraries with jQuery dependancies it will always be there, at best you could have this along side jQuery 2.0. If you only want dependant jQuery 1.x this wont work and you'll have to look at Dave R's answer Feb 3, 2014 at 21:38
4

I combined the two solutions from the top for @TeYoU

First I Installed the package from the package manager console:

Tools Menu -> Library Package Manager -> Package Manager Console

PM> Install-Package jQuery -Version 1.9.1

Then I edited the packages.config as @Dave R. says:

<package id="jQuery" version="1.9.1" allowedVersions="[1.9.1,2)" />

Then I updated to the current version, currently 1.10.2 using Nuget Manager and it worked like a charm.

1
  • 1
    you actually don't need to specify the version on the first one I found. if you add the allow versions, then run an update, it will downgrade you...
    – Martin
    Sep 20, 2013 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.