【问题标题】:setting debug='false' in web.config causes bundling to fail在 web.config 中设置 debug='false' 会导致捆绑失败
【发布时间】:2013-11-26 16:44:46
【问题描述】:

当我在不调试的情况下更改为运行时,我的捆绑没有在 html 中包含正确的路径。它正在删除文件名。

using System.Web;
using System.Web.Optimization;

namespace Search
{
    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.UseCdn = true;

            var jqueryuiCdnPath = "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/jquery-ui.min.js";
            var knockoutCdnPath = "http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js";
            var modernizerCdnPath = "";

            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js",
                        "~/Scripts/jquery.printPage.js"
                        ));

            bundles.Add(new ScriptBundle("~/bundles/jqueryui", jqueryuiCdnPath).Include(
                        "~/Scripts/jquery-ui-{version}.custom.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.unobtrusive*",
                        "~/Scripts/jquery.validate*"));

            bundles.Add(new ScriptBundle("~/bundles/knockout", knockoutCdnPath).Include(
                "~/Scripts/knockout-2.1.0.debug.js"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/scpa").Include(
            "~/Scripts/scpa.js"));


            bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/NewSite.css").Include("~/Content/PagedList.css"));


            bundles.Add(new StyleBundle("~/Content/themes/redmond").Include(
                        "~/Content/themes/redmond/jquery-ui-{version}.custom.css"));
        }
    }
}

我的 _layout.cshtml 中的这些行

    @Styles.Render("~/content/themes/redmond")
    @Styles.Render("~/content/css")

在启用调试的情况下生成以下 html

<link href="/Content/themes/redmond/jquery-ui-1.10.3.custom.css" rel="stylesheet"/>
<link href="/Content/NewSite.css" rel="stylesheet"/>
<link href="/Content/PagedList.css" rel="stylesheet"/>

但是在调试关闭时会生成这个

<link href="/content/themes/redmond?v=vAH9QfqxdFYSzS_GtpWa8fGJ5s-xvZ9vhODh9AGxIbo1" rel="stylesheet"/>
<link href="/content/css?v=3o7zDFviiGqrSMyW4LTNH-J9tRGdIoONnnh_FMEm4Mg1" rel="stylesheet"/>

【问题讨论】:

  • 请解释你的反对票。

标签: c# asp.net-mvc bundling-and-minification


【解决方案1】:

它应该是这样生成的。

尽管您的第一个包可能无法正常工作——您不能为包名指定与现有文件夹相同的名称。重命名第二个 StyleBundle,如:

bundles.Add(new StyleBundle("~/Content/cssRedmond").Include(...

因为它生成的链接会起作用,因为它不会与另一个文件夹冲突:

<link href="/content/cssRedmond?v=..."  //This is OK
<link href="/content/themes/redmond?v=..." //Not OK. Conflicts with folder

【讨论】:

  • 感谢您的帮助,我从阅读有关捆绑的信息中不明白它会完全删除对发布文件名的引用。
  • @Mr.Manager 那是“捆绑”部分......文件被缩小/合并到一个文件中。所以现在客户端只需要下载一个文件而不是多个文件。
猜你喜欢
  • 2013-02-14
  • 1970-01-01
  • 1970-01-01
  • 2012-12-25
  • 1970-01-01
  • 1970-01-01
  • 2017-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多