asp.mvc视图enteres #IF DEBUG在释放构(asp.mvc view entere

2019-07-04 19:59发布

我在那里有下列语句的ASP MVC视图

#if DEBUG
  //section 1
  //do stuff
#else
  //section 2
  //do other stuff
#endif

当在Visual Studio中,我选择从下拉列表中发布配置做构建,代码仍然可以通过第1节步骤。

在溶液中配置属性解决方案的所有子项目被设置为释放配置。

什么我没有得到吗?

Answer 1:

要明白,有两种,完全独立的,汇编为您的项目是非常重要的。 首先是在Visual Studio做一个。 第二个是ASP.NET页面是否送达之前的一个。 您的视图内的DEBUG如果在第二步完成。 您所描述的发布版本是第一步。 因此,项目的调试/发布的设置有什么都没有做在Web.config中/ ASP.NET的编译器调试设置。

此外,为您的Visual Studio构建以改变在Web.config调试设置这将是完全不恰当的。 这是两个独立汇编,和一个不应该影响其他。

在另一方面,你可能有,让你的看法不同的表现,当你正在调试的Visual Studio里面一个完全合理的需求,你可以做到这一点。 你只需要移动的“如果”语句视图之外,进入一些东西,由Visual Studio编译的,而不是ASP.NET。 我们这样做是用HTML帮手。 例如:

        /// <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. ...

这包括调试JS文件在调试配置在Visual Studio中运行时,但最小JS除外。



Answer 2:

设置<compilation debug="false">在您web.config文件。



Answer 3:

检查项目的设置,以确保DEBUG没有定义。



文章来源: asp.mvc view enteres #IF DEBUG in release configuration