Automatically updating script references when updating jquery and modernizr with NuGet
After noticing that my client-side validation had stopped working, I determined that my html script references for jquery and modernizr were out of date. I immediately realized that this was because I had recently updated all my NuGet packages, so the version numbers no longer matched.
Here is the markup in question (after manually updating the version numbers):
<script src="@Url.Content("~/Scripts/jquery-1.6.3.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-2.0.6.min.js")" type="text/javascript"></script>
This is a maintenance issue. Basically, it appears that I have to manually increment the version numbers in my script references every time I use NuGet to update all my packages. This is at best an inconvenience, and at worst, something I'll just forget to do entirely, especially given that there are no warnings when performing the update in NuGet or during compilation.
Two questions:
What can I do to improve the update process so that version numbers get updated automatically, or at least, receive a warning that my scripts references are incorrect? (Note: I already have MvcBuildViews turned on.)
Why do jquery and modernizr have version numbers in the file name while other scripts (such as jquery.validate and jquery.validate.unobtrusive) don't? It seems like the proble开发者_StackOverflow中文版m could be solved by keeping version numbers out of file names.
As far as I know, modifying the files via nuget is not possible. That would be insecure as well.
I am currently bundling my js files into one and when I update my jquery files, I go there and change it.
If JQuery does not include file version number, that would cause some breaks on your code if any breaking change occurs.
I just installed elmah to log errors on my website. It turns out that, if a script
tag in html refers to a file that doesn't exist, this will trigger an error on elmah. Since I have elmah configured to send me emails when errors are encountered, this provides a decent enough alerting mechanism for outdated script references. Receiving an actual compile error or warning would be preferable, but elmah at least prevents the problem from going unnoticed.
精彩评论