gpt4 book ai didi

visual-studio-2013 - 启用 MVC 5.1 调试不会禁用捆绑和缩小

转载 作者:行者123 更新时间:2023-12-04 16:09:45 24 4
gpt4 key购买 nike

从 VS 2013.2RTM Pro、MVC 5.1 应用程序在调试中运行。

如果编译模式设置为 debug="true"它应该禁用捆绑和缩小,但它没有。当我检查页面上的查看源时,样式和脚本是捆绑在一起的。<script src="/bundles/modernizr?v=K-FFpFNtIXjnmlQamnX3qHX_A5r984M2xbAgcuEm38iv41"></script>
如果我设置 BundleTable.EnableOptimizations = false;在 BundleConfig.cs 中,它确实禁用了捆绑和缩小,但这不是它应该如何工作的。我不应该记得切换 EnableOptimizations环境!

在 VS 2012 MVC 4 应用程序中一切正常。

这是 MVC 5.1 错误吗?有没有其他人有这个问题?有没有办法让调试禁用捆绑和缩小?
web.config:

  <system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" useFullyQualifiedRedirectUrl="true" maxRequestLength="100000" enableVersionHeader="false" />
<sessionState cookieName="My_SessionId" />
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
</system.web>
_Layout.cshtml:
在标题中
@Styles.Render("~/Content/css") @Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/modernizr")

在 body 的末端
@Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jqueryui") @Scripts.Render("~/bundles/jqueryval")

最佳答案

你可以看看这篇文章
http://codemares.blogspot.com.eg/2012/03/disable-minification-with-mvc-4-bundles.html

或者你可以使用这个简单的实现

public class NoMinifyTransform : JsMinify
{
public override void Process(BundleContext context, BundleResponse response)
{
context.EnableOptimizations = false;
var enableInstrumentation = context.EnableInstrumentation;
context.EnableInstrumentation = true;
base.Process(context, response);
context.EnableInstrumentation = enableInstrumentation;
}
}

然后在 (App_Start) 中定义您的脚本包时,您可以像这样使用基础 Bundle 类
            IBundleTransform jsTransformer;
#if DEBUG
BundleTable.EnableOptimizations = false;
jsTransformer = new NoMinifyTransform();
#else
jstransformer = new JsMinify();
#endif
bundles.Add(new Bundle("~/TestBundle/alljs", jsTransformer)
.Include("~/Scripts/a.js")
.Include("~/Scripts/b.js")
.Include("~/Scripts/c.js"));

关于visual-studio-2013 - 启用 MVC 5.1 调试不会禁用捆绑和缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23707200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com