【问题标题】:In MVC 4, release mode is not generating .min version在 MVC 4 中,发布模式不会生成 .min 版本
【发布时间】:2013-07-25 14:07:02
【问题描述】:

我在 Windows 7 64 上的 VS 2012 Ultimate Release 3 中创建了一个默认 Internet(并尝试了 Intranet——同样的问题)MVC 4 文件。然后我将发布模式设置为发布而不是调试,并运行应用程序。

在IE 9中,我右键选择查看源,使用的jquery文件和debug模式下的一样(不是.min版本):

<script src="/Scripts/jquery-1.8.2.js"></script>

在发布模式下,我还应该做些什么来启用自动使用 .min 版本的脚本文件?我还尝试修改代码以检查是否定义了调试(#if DEBUG)并且没有。

请注意,我使用 MVC 4 附带的模板创建的默认应用程序对此进行了测试。我根本没有更改它们(我最初在自己的应用程序中遇到了问题,想看看是不是我已经完成了)。

网络配置是默认配置。发行版是:

<!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an atrribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your Web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>

谢谢, -D

【问题讨论】:

  • 你的release.web.config的内容是什么
  • 我已经用 release.web.config 更新了消息。

标签: asp.net-mvc-4 minify bundling-and-minification


【解决方案1】:

我发现另一条消息 (Running an ASP.NET MVC 4 app in release mode does not bundle and minifiy the js files) 有一个解决方法可以使它工作。基本上,我将以下内容添加到Global.asax.cs 中的Application_Start

#if !DEBUG 
    BundleTable.EnableOptimizations = true; 
#endif 

这修复了它(或者至少,使它的行为符合我的预期)。

谢谢,

-D

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 2018-06-29
    相关资源
    最近更新 更多