updating Visual Studio templates on new release of jQuery (and other libraries)
Now that Visual Studio => 2010 has jQuery support, I'm wondering how I can upda开发者_如何转开发te the project template when a new jQuery release comes out? Currently when you create a project, it automatically creates the 1.4.1 files (in VS2010), but jQuery is ever evolving, and often updates it version.
How can I tell Visual Studio to use the more recent version of jQuery (or other libraries for that matter)?
You can use NuGet
- right-click on your project in Solution Explorer
- click on "Manage NuGet Packages" in context menu
- type "jQuery" in the search box on the top right corner of the dialog box
- press Enter key and wait for results
- look for "jQuery" in the results, SELECT it and click "Install" button
- (after installation, you previous jquery and related files will be replaced with the latest ones)
Alternatively, you can create an Empty project and install the the nuget package(s) through the Package Manager Console. This can include ALL of the libraries that you default to.
PM> Install-Package jQuery
From there, save it as a new template, and whenever you create a new project, simply run the following terminal command before starting work.
PM> Update-Package
more info on Update-Package
You can create a new project template with jQuery 1.4.2 included: http://msdn.microsoft.com/en-us/library/ms247120%28v=VS.100%29.aspx
Automatic update have some issues. If you are using jQuery library with some additional plugin and they depend on the previous jQuery library framework then they will not work. That is why you need to think carefully before updating the jQuery library from version to version.
UPDATE:
You could modify an existing template for Visual Studio which will allow you to refer to the new version of jQuery. Here is an article about creating custom Visual Studio templates.
http://msdn.microsoft.com/en-us/library/ms247119(v=VS.80).aspx
This whole Nuget/update version model in JQuery is a huge mess! (Who designed this system?)
What I do is simply avoid the JQuery template piece in Visual Studio and place the current JQuery javascript links in ONE PLACE in your web project so its pasted into every single page......either the MVC Layout page, usercontrol, or masterpage. You can mix and match controls. But it doesnt matter as modern browsers cache these files after the first download anyway.
Now when you do a JQuery update, you can fix it in one simple place in your web project. All ECMAscripts have been done this way anyway the past 15 years using server side includes or other strategies. I'm still not sure why you want a template to stuff links in hundreds of view pages in MVC you now have to customize one by one when you get different versioned files names. I think ASP.NET MVC has gone backwards in its design for that reason.
精彩评论