ASP.NET Web表单BundleTable仍然在调试模式下捆绑

Mar*_*eel 1 asp.net bundling-and-minification asp.net-optimization

我有一个ASP.NET Web表单应用程序,使用Microsoft.AspNet.Web.Optimization包中的新Bundling和Minification功能在.NET 4.5上运行.

到目前为止,这是一个非常简单的设置,只需一个捆绑.

BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/send").Include(
        "~/scripts/GrowingInput.js", 
        "~/scripts/textboxlist/TextboxList.js",
        "~/scripts/textboxlist/TextboxList.Livesearch.js",
        "~/scripts/combobox/ui.combobox.js",
        "~/scripts/jquery-ui-timepicker.js",
        "~/scripts/msp.send.js"));
}
Run Code Online (Sandbox Code Playgroud)

Global.asax中

protected void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Run Code Online (Sandbox Code Playgroud)

Send.aspx

<%: Scripts.Render("/bundles/send") %>
Run Code Online (Sandbox Code Playgroud)

这始终在Web浏览器中呈现为<script src="/bundles/send"></script>忽略在web.config中将debug设置为true还是false.

我已经尝试添加BundleTable.EnableOptimizations = false;到BundleConfig.cs以强制捆绑,但这没有任何区别.

希望得到以下工作,就像在MVC网站中一样(Microsoft文档似乎建议Web表单应该是相同的).

  1. 使用调试标志打开/关闭捆绑
  2. 附加缓存清除?v = xxx查询字符串以进行版本控制.

Hao*_*ung 5

Bundles路径必须以〜开头,但Scripts.Render方法不仅限于bundle,因此它只将url视为本地资源,(它使用BundleTable.Bundles.GetBundleFor(path)来确定url是否为bundle)

你只需添加一个〜就像这样工作: <%: Scripts.Render("~/bundles/send") %>