使用 NuGet 更新 jquery 和现代化时自动更新脚本引用

发布于 2024-12-05 03:27:16 字数 757 浏览 0 评论 0原文

在注意到我的客户端验证已停止工作后,我确定 jquery 和 Modernizr 的 html 脚本引用已过时。我立即意识到这是因为我最近更新了所有 NuGet 包,因此版本号不再匹配。

这是有问题的标记(手动更新版本号后):

<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>

这是一个维护问题。基本上,每次使用 NuGet 更新所有包时,我似乎都必须手动增加脚本引用中的版本号。这充其量是一种不便,而最坏的情况是,我会完全忘记这样做,特别是考虑到在 NuGet 中或编译期间执行更新时没有警告。

两个问题:

  • 我可以做些什么来改进更新过程,以便版本号自动更新,或者至少收到关于我的脚本引用不正确的警告? (注意:我已经打开了 MvcBuildViews。)

  • 为什么 jquery 和 Modernizr 在文件名中包含版本号,而其他脚本(例如 jquery.validate 和 jquery.validate.unobtrusive)却没有?看来这个问题可以通过将版本号排除在文件名之外来解决。

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 problem could be solved by keeping version numbers out of file names.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方。的韩爷 2024-12-12 03:27:16

据我所知,通过 nuget 修改文件是不可能的。那也会缺乏安全感。

我目前正在将我的 js 文件捆绑到一个文件中,当我更新我的 jquery 文件时,我会去那里更改它。

如果 JQuery 不包含文件版本号,那么如果发生任何重大更改,就会导致代码中断。

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.

你另情深 2024-12-12 03:27:16

我刚刚安装了 elmah 来记录我网站上的错误。事实证明,如果 html 中的 script 标记引用了不存在的文件,则会在 elmah 上触发错误。由于我将 elmah 配置为在遇到错误时向我发送电子邮件,因此这为过时的脚本引用提供了足够好的警报机制。收到实际的编译错误或警告会更好,但 elmah 至少可以防止问题被忽视。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文