ASP.NET:如何在调试模式下编译?
AFAIK,当 web/app-config 设置“compilation”具有 debug="false" 时,通常的 ASP.NET 网站/Web 应用程序会打开到 DEBUG 模式。
但我不太清楚它是如何工作的。让我们考虑一个例子:
我有
。我已将以下行添加到“Page_Load”方法中:
System.Diagnostics.Debug.WriteLine("Page_Load");
当我以“调试”模式启动网站时(使用 F5 按钮),它将我的“Page_Load”放入输出窗口。到目前为止一切都很好。
当我将应用程序编译模式更改为非调试时:
它会重新编译“非调试”模式的所有内容吗?仅通过此更改就足以进入“生产”环境吗?
我想,对于不使用其他项目的网站来说应该足够了。否则,我最好将整个配置切换到“发布”模式。在这种情况下,每个项目都将以“发布”模式重新编译。
我说得对吗?如果这里有问题,你能指出我吗?
多谢!
AFAIK, usual ASP.NET web site/web application switched on into DEBUG mode when web/app-config setting "compilation" has debug="false".
But I don't clearly understand how it works. Let's consider example:
I have <compilation debug="true" />
. I've added the following line into "Page_Load" method:
System.Diagnostics.Debug.WriteLine("Page_Load");
When I launched web-site in 'debug' mode (using F5 button) It put me 'Page_Load' into output window. Everything is ok so far.
When I change application compilation mode into non-debug:
Will it recompile everything for 'non-debug' mode? Is this enough to go into "production" environment with this change only?
I guess, it should be enough for web-site that doesn't use other project. Otherwise, I would better switch whole configuration into "Release" mode. In this case EACH project will be recompiled in "Release" mode.
Am I right? Could you please point me if something is wrong here?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于你的问题的要点是在 Visual Studio 的调试/发布模式下编译和 Web.config 的调试标志之间的区别。
我会尽力向你们俩解释。
首先,您必须了解 ASP.NET 应用程序是如何编译的,否则您将无法理解两种编译之间的区别。
ASP.NET 应用程序由标记(即 .aspx 页面、.ascx 控件、.ashx .asmx 标记文件)和代码隐藏组成。代码隐藏,从 IDE 的角度来看(无论是 Visual Studio、MonoDevelop 等)是一个 .NET 类库,即。一组不单独执行任何操作的类。这些可以通过 IDE 设置无差别地编译为 Debug 或 Release 模式。如果编译为发布模式,则对 Debug 类的调用将被忽略。
那么标记呢?当您启动 Web 应用程序时,应用程序服务器将编译标记文件以获得最终的程序集。例如,带有代码隐藏文件的
Default.aspx
页被编译为最终类,该类继承代码隐藏类并将其所有静态内容写入 HTTP 输出部件,以及在设计期间选择的位置中在基类中实例化的所有控件。内联代码(即标记)也会被编译。为了选择编译模式,使用 Web.config 中的调试标志,因为您无法通过简单地反映程序集来确定它是否已在调试或发布模式下编译(尽管可能有一些经验标准) )。
简而言之,
Debug
类时,请确保您的 IDE 将网站编译为调试模式。Debug
类时,确保你设置了 Web.config 的调试标志xbuild
它),我不确定,但我相信调试标志也将用于第一个编译阶段,我希望我有所帮助!
The point about your question is the difference between compiling in Visual Studio's Debug/Release modes and the Web.config's debug flag.
I'll try to explain you both.
First of all, you must get to know how an ASP.NET application is compiled, otherwise you won't understand the difference between the two compilations.
An ASP.NET application is made by markup (ie. .aspx pages, .ascx controls, .ashx .asmx marker files) and code-behind. Code-behind, from your IDE's point of view (no matter Visual Studio, MonoDevelop, etc.) is a .NET Class Library, ie. a set of classes that don't do anything alone. These can be compiled into Debug or Release mode indifferently by IDE setting. If you compile into Release mode, then calls to
Debug
class will be ignored.What about markup? When you start the web application, the markup files get compiled by the application server to get the final assemblies. For example, a
Default.aspx
page with a code-behind file is compiled into a final class that inherits the code-behind class and writes to HTTP output all of its static parts, plus all the controls instantiated in the base class in the positions that have been chosen during design. Inline code (ie.<script runat=server>
tags) gets compiled too. In order to choose the compilation mode, the debug flag in Web.config is used, because you can't determine for sure if an assembly has been compiled in debug or release mode by simply reflecting on it (though there could be some empyrical criteria).In a few words
Debug
class from code-behind, make sure that your IDE compiles the website into Debug modeDebug
class from inline code in markup, make sure you have Web.config's debug flag setxbuild
it), I'm unsure but I believe the debug flag will be used for first compilation stage tooI hope I have been of help!
据我了解,当您更改网站的 web.config 以禁用调试时,JIT 将从头开始 - 因为 System.Diagnostics.Debug 命名空间中的所有方法都被标记为仅包含在调试模式(
[Conditional("DEBUG")]
)下,发布版本中根本不会出现调用。对于调试模式下的预编译的 Web 应用程序,这些调用将在生成的 DLL 中,此时禁用调试对您没有帮助 - 您需要在发布模式下重建/预编译 Web 应用程序,然后再发布它。
As I understand it when you change the web.config for a Web Site to disable debugging, the JIT will start from scratch - since all methods in the System.Diagnostics.Debug namespace are marked to be only included in debug mode (
[Conditional("DEBUG")]
) the calls won't be there at all in the release build.For a precompiled Web application in debug mode these calls will be in the DLLs produced, disabling debug at that point will not help you - you need to rebuild/precompile the Web application in release mode before releasing it.