asp.mvc观点enteres #IF DEBUG在发布配置 [英] asp.mvc view enteres #IF DEBUG in release configuration

查看:297
本文介绍了asp.mvc观点enteres #IF DEBUG在发布配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an ASP MVC view where have the following statement

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

在Visual Studio中,我选择从下拉列表中发布配置做打造,code仍可通过第1部分的步骤。

When in visual studio I choose the release configuration from the dropdown to do the build, the code still steps through section 1.

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

In the solution configuration properties all subprojects of the solution are set to the release configuration.

我是什么没有得到在这里?

What am I not getting here?

推荐答案

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

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.

此外,这将是完全不适合您的Visual Studio生成改变在Web.config调试设置。这些是两个单独的汇编,和不应该影响到其他

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.

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

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

这包括调试JS文件在Visual Studio调试配置中运行时,但最小化,否则JS

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

这篇关于asp.mvc观点enteres #IF DEBUG在发布配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆