我能让 Nuget 保持在 jQuery 1.9.x/1.x 的路径上(而不是升级到2.x)吗?

像大多数人一样,我使用 JQuery Nuget 包来跟上时代。

但是,随着 jQuery 2.0的发布,我现在需要将 jQuery 1.9.1升级到2.0。现在我的网站上有足够多的访问者使用“古老”版本的浏览器,我宁愿坚持使用1.9. x 和 JQuery 迁移

在检查包的更新(jQuery 或其他)时,有没有办法告诉 Nuget 坚持使用特定的版本(1.9.x) ?

我正在使用 Visual Studio 2010/2012扩展,但是如果我需要使用 VS 中的命令行界面来解决这个问题,我当然会这样做。

注意: 在我的脑海中有一件事是他们搞砸了更新。因为 jQuery 1.9.x 和2.0.x/2.x 有很大的不同,看起来他们应该创建一个 jQuery 2(. 0。谢谢。X)包装。

当然,那些真正想要升级到2.x 版本的用户必须知道这一点,并且切换到他们想要安装的软件包。但是考虑到它包含了突破性的改变,也许这样更好?

12562 次浏览

how about to specify the version?

PM> Install-Package jQuery -Version 1.9.1

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

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

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.

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.