在MVC 4中,发布模式不生成.min版本

时间:2013-07-25 14:07:02

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

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

在IE 9中,我右键单击并选择了视图源,正在使用的jquery文件与调试模式中的jquery文件相同(不是.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

1 个答案:

答案 0 :(得分:0)

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

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

这修复了它(或者至少使它的行为与我预期的行为方式相同)。

谢谢,

-D