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?

James Skemp
  • 8,018
  • 9
  • 64
  • 107
  • 2
    Since 1.10.x is out, I've updated the title to make it a bit more clear. – James Skemp May 26 '13 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 '13 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 – James Skemp Jun 28 '13 at 21:53

4 Answers4

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'.)

Dave R.
  • 7,206
  • 3
  • 30
  • 52
  • 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 – James Skemp Apr 22 '13 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 '13 at 23:25
  • Thanks Dave, that does help. And thanks for pointing out the allowedVersions attribute. I was aware of something similar for creating packages, but didn't realize you could use it the other way as well. Unfortunate that both branches will be in one, though :| – James Skemp Apr 24 '13 at 12:20
  • This should say 1.x and 2.x paths, not 1.9 and 2.0. There will be 1.10 API-compatible with 2.0, 1.11 API-compatible with 2.1 etc. – mgol Apr 27 '13 at 07:57
  • 2
    The NuGet UI has a [bug](https://nuget.codeplex.com/workitem/3301) 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. – Edward Brey Apr 28 '13 at 13:03
  • @m_gol - Thanks for the feedback. I'll update the answer to refer to 1.x and 2.x instead of the current versions. – Dave R. Apr 30 '13 at 18:25
  • @EdwardBrey make sure you use the updated version of the code that says anything less than version 2 `allowedVersions="[1.9.1,2)"`. That should allow you to update the latest 1.x (1.10.1 right now) – John Jun 19 '13 at 12:09
  • 2
    I've seen that there's now a `jquery1` package on nuget, which only tracks the 1.x branch. – Chris J Sep 26 '13 at 07: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 – RockResolve Feb 03 '14 at 21:45
  • @DaveR. it looks like there are now [no plans](http://nugetpackages.codeplex.com/workitem/9) to have a jQuery 1.x package supported by the [NuGet Community Packages](http://nugetpackages.codeplex.com/) team. – Kevin Kuszyk Feb 26 '14 at 11:56
  • Hmm, I've just put this code into my package.config file but nuget is still prompting me to update to 2.1.1 – Jammer Jun 17 '14 at 20:28
  • I know this is an older post, but I keep coming back to this over and over and was hoping Dave could update his answer to allowedVersions="[1.11.2,2.0.0)" as the new nuget does not like the syntax any longer resulting in VS stability issues when browsing nuget packages. – Mirko Mar 18 '15 at 13:23
  • @Mirko I've just tried the update from 1.9.1 to 1.11.2 without issue, using both the Package Manager Console and the UI. I'm using NuGet 2.8.50926.664 on Visual Studio 2013. Is the issue in the list on http://nuget.codeplex.com/workitem/list/basic ? I'm reticent about editing the answer, as the question includes the jQuery version explicitly. – Dave R. Mar 19 '15 at 11:49
19

how about to specify the version?

PM> Install-Package jQuery -Version 1.9.1

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

TeYoU
  • 844
  • 7
  • 13
  • Related question I asked: http://stackoverflow.com/q/16126338/11912 In short, it works, but it's klunky. And a blind update breaks it. – James Skemp Apr 22 '13 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. – James Skemp Jun 28 '13 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 '14 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.

Chris J
  • 30,688
  • 6
  • 69
  • 111
  • 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. – James Skemp Sep 26 '13 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. – James Skemp Sep 26 '13 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 – RockResolve Feb 03 '14 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.

jmacboy
  • 323
  • 3
  • 16
  • 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 '13 at 12:03