ASP.NET MVC应用程序4与捆绑和缩小,所以在调试模式下启用缩小? [英] ASP.NET MVC 4 app with bundling and minification, why is minification enabled in debug mode?

查看:343
本文介绍了ASP.NET MVC应用程序4与捆绑和缩小,所以在调试模式下启用缩小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚迁移的ASP.NET MVC 3项目MVC 4 / .NET 4.0,而为了安装的NuGet包 Microsoft.AspNet.Web.Optimization 来支持捆绑和CSS和JavaScript的缩小。的总是的启用我有pretty有多少钱捆绑/缩小的工作,问题是它的。即使该应用程序是在调试模式下,在Web.config中配置,所有的JavaScript都包括精缩。正如你可以从下面的XML代码段看到,调试模式在Web.config中启用:

I've just migrated an ASP.NET MVC 3 project to MVC 4 / .NET 4.0, and installed NuGet package Microsoft.AspNet.Web.Optimization in order to support bundling and minification of CSS and JavaScript. I've pretty much got bundling/minification working, the problem is it's always enabled. Even though the app is in debug mode, as configured in Web.config, all JavaScript includes are minified. As you can see from the below XML snippet, debug mode is enabled in Web.config:

<system.web>
  <compilation debug="true" targetFramework="4.0">
    ...
  </compilation>
  ...
</system.web>

我的包配置的摘录:

An excerpt of my bundle configuration:

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        ...

        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-1.*",
                    "~/Scripts/jquery.form.js",
                    "~/Scripts/jquery.format.js"));

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

        ...
    }
}

CSS / JavaScript的包括在HTML呈现为例如:

CSS/JavaScript includes are rendered in the HTML as for example:

<link href="/content/css" rel="stylesheet" type="text/css">
<script src="/bundles/jquery" type="text/javascript"></script>

没有人有任何线索,为什么缩小在我的情况下被启用?我在茫然,我错过了什么在这里。要解决我创建了一个测试ASP.NET MVC 4的互联网应用,并可以验证的CSS / JavaScript的做的的精缩得到在调试模式下为这个项目。

Does anyone have any clue as to why minification gets enabled in my case? I am at a loss as to what I'm missing here. To troubleshoot I created a test ASP.NET MVC 4 Internet application and could verify that CSS/JavaScript did not get minified in debug mode for this project.

编辑:

在我_Layout.cshtml文件I渲染样式/脚本是这样的:

In my _Layout.cshtml file I render the styles/scripts like this:

@Styles.Render("content/css")
@Scripts.Render("bundles/jquery")

感谢浩,我意识到,我已经忘了preFIX以包名〜/\".

Thanks to Hao, I realize that I've forgot to prefix the bundle names with "~/".

推荐答案

红旗在你的HTML渲染的链接/ script标签:

The red flag is with the link/script tags rendered in your HTML:

这些应该包含版本散列code。如果是使用脚本/ Style.Render,即

These should contain a version hashcode if you are using Script/Style.Render, i.e.

< script src="/bundles/jquery?v=wvLq7H7qEZB2giyIRn7aEZAxhHOb2RfTYYh2HMd9EqM1"/>

要获得该MVC4模板使用,您必须使用脚本/ Style.Render方法以及调试/释放行为。调用这些方法时,你必须通过虚拟束的路径,在你的例子:

To get the debug/release behavior that the MVC4 templates are using, you must use the Script/Style.Render methods as well. When calling these methods, you must pass virtual bundle paths, in your example:

@Styles.Render("~/content/css")
@Scripts.Render("~/bundles/jquery")

在调试模式下,你不应该得到的包(这将永远是精缩/捆绑)链接/ script标签指向。相反,你应该得到脚本/链接标签个别资源在调试模式。

In debug mode, you should not get link/script tags pointing at the bundle (which will always be minified/bundled). Instead you should be getting script/link tags to the individual resources in debug mode.

这篇关于ASP.NET MVC应用程序4与捆绑和缩小,所以在调试模式下启用缩小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆