asp.mvc view enteres #IF DEBUG in release configuration

前端 未结 3 1132
滥情空心
滥情空心 2020-12-31 03:00

I have an ASP MVC view where have the following statement

#if DEBUG
  //section 1
  //do stuff
#else
  //section 2
  //do other stuff
#endif
<
相关标签:
3条回答
  • 2020-12-31 03:41

    It is important to understand that there are two, entirely separate, compilations for your project. The first is the one you do in Visual Studio. The second is the one which ASP.NET does just before the page is served. The if DEBUG inside your view is done in the second step. The release build you describe is the first step. Therefore, your project's debug/release setting has nothing at all to do with the debug setting in Web.config/the ASP.NET compiler.

    Moreover, it would be completely inappropriate for your Visual Studio build to change the debug setting in the Web.config. These are two separate compilations, and one should not affect the other.

    On the other hand, you probably have a perfectly reasonable need for making your view behave differently when you are debugging inside of Visual Studio, and you can do this. You just need to move the "if" statement outside of the view and into something which is compiled by Visual Studio, instead of ASP.NET. We do this with an HTML helper. For example:

            /// <summary>
            /// Returns the HTML to include the appropriate JavaScript files for 
            /// the Site.Master.aspx page, depending upon whether the assembly 
            /// was compiled in debug or release mode.
            /// </summary>
            /// <returns>HTML script tags as a multi-line string.</returns>
            public static string SiteMasterScripts(this UrlHelper helper)
            {
                var result = new StringBuilder();
    #if DEBUG
                result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", helper.Content("~/Content/js/MicrosoftAjax.debug.js"));
    #else
                result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", helper.Content("~/Content/js/MicrosoftAjax.js"));
    #endif
            // etc. ...
    

    This includes debug JS files when running in debug configuration in Visual Studio, but minimized JS otherwise.

    0 讨论(0)
  • 2020-12-31 03:41

    Set <compilation debug="false"> in your web.config file.

    0 讨论(0)
  • 2020-12-31 03:43

    Check your project's setting to ensure that DEBUG is not defined.

    0 讨论(0)
提交回复
热议问题