I have an ASP MVC view where have the following statement
我有一个ASP MVC视图,其中有以下语句
#if DEBUG
//section 1
//do stuff
#else
//section 2
//do other stuff
#endif
When in visual studio I choose the release configuration from the dropdown to do the build, the code still steps through section 1.
在visual studio中,我从下拉列表中选择发布配置来进行构建,代码仍然会逐步完成第1部分。
In the solution configuration properties all subprojects of the solution are set to the release configuration.
在解决方案配置属性中,解决方案的所有子项目都设置为发布配置。
What am I not getting here?
我没有到这里来的是什么?
3 个解决方案
#1
31
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中执行的操作。第二个是ASP.NET在提供页面之前执行的操作。视图中的if DEBUG是在第二步中完成的。您描述的发布版本是第一步。因此,您的项目的调试/发布设置与Web.config / ASP.NET编译器中的调试设置完全没有任何关系。
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构建更改Web.config中的调试设置是完全不合适的。这是两个单独的编辑,一个不应该影响另一个。
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:
另一方面,当您在Visual Studio内部进行调试时,您可能非常需要使视图的行为不同,并且您可以执行此操作。您只需要在视图外部移动“if”语句,并将其移动到由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. ...
This includes debug JS files when running in debug configuration in Visual Studio, but minimized JS otherwise.
这包括在Visual Studio中的调试配置中运行时调试JS文件,否则最小化JS。
#2
3
Set <compilation debug="false">
in your web.config
file.
在web.config文件中设置
#3
0
Check your project's setting to ensure that DEBUG is not defined.
检查项目的设置以确保未定义DEBUG。
#1
31
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中执行的操作。第二个是ASP.NET在提供页面之前执行的操作。视图中的if DEBUG是在第二步中完成的。您描述的发布版本是第一步。因此,您的项目的调试/发布设置与Web.config / ASP.NET编译器中的调试设置完全没有任何关系。
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构建更改Web.config中的调试设置是完全不合适的。这是两个单独的编辑,一个不应该影响另一个。
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:
另一方面,当您在Visual Studio内部进行调试时,您可能非常需要使视图的行为不同,并且您可以执行此操作。您只需要在视图外部移动“if”语句,并将其移动到由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. ...
This includes debug JS files when running in debug configuration in Visual Studio, but minimized JS otherwise.
这包括在Visual Studio中的调试配置中运行时调试JS文件,否则最小化JS。
#2
3
Set <compilation debug="false">
in your web.config
file.
在web.config文件中设置
#3
0
Check your project's setting to ensure that DEBUG is not defined.
检查项目的设置以确保未定义DEBUG。