Visual Studio-调试与发布 [英] Visual Studio - Debug vs Release

查看:113
本文介绍了Visual Studio-调试与发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2008中构建了一个针对.NET 2.0的Windows服务.我将其作为控制台应用程序运行以对其进行调试.

控制台应用程序运行良好.我将其作为服务放在本地计算机上,以调试模式进行编译,但仍然可以正常工作.我现在准备发布,突然,当我将其设置为发布模式时,该服务便会编译并安装,但没有任何反应. (服务中没有任何代码在运行).

我意识到发布与调试模式是属性配置设置,但是似乎在发布模式下,即使我选中了定义DEBUG常量,取消选中优化代码"并将调试信息"设置为完整",它仍然无济于事.

将其重新设置为调试,它再次像魅力一样工作.

(作为附带说明,我尝试将目标框架重置为3.5,以确保这也不是问题)

所以我的问题(按重要性排序)是:

  1. 以任何方式使用我的调试"版本会导致任何问题吗?

  2. 除我已经尝试更改的三个设置外,调试和发行版之间还有哪些不同设置?

  3. 对我来说,这似乎是一个奇怪的错误,并且激起了我的好奇心.你知道是什么原因造成的吗?

应该提到,我已经在使用自定义安装程序了.基本上,我会编译该程序(在调试或发行版本中),然后使用相应的安装程序进行安装.

解决方案

1)可能(如果不是直接的话)是通过使应用程序变慢并使其使用更多的内存来间接实现的.

2)当它在调试模式下运行时,某些功能会有所不同,例如:

  • 该代码是用一些额外的NOP指令编译的,因此在每一行代码的开头至少有一条指令,因此可以在任何行上放置一个断点.

  • 可以在释放模式下重新排列指令,但不能在调试模式下重新排列指令,从而使代码可以单步执行,并且结果将与源代码的确切顺序相对应.

  • 垃圾收集器的工作原理有所不同,它使引用在整个作用域中生存,而不是仅在使用它们的时间内生存,因此可以在调试模式下查看变量,而在作用域结束之前不会消失. p>

  • 异常包含更多信息,并且引发异常时处理时间更长.

所有这些差异都相对较小,但它们是实际差异,在某些情况下可能会很重要.

如果您看到调试模式和释放模式之间的性能差异很大,通常是因为代码有问题,例如,如果它抛出并捕获了大量异常.如果代码中存在争用条件,则可能仅在发布模式下发生,因为调试模式下会产生一些额外的开销,从而使代码的运行速度稍慢.

3)至于您的服务的问题是什么,我不知道,但这似乎与在调试模式或发布模式下如何执行代码无关.该代码无论如何都将启动,如果该代码有问题,它将崩溃,并且您可以在事件日志中看到它.

I built a windows service, targeted for .NET 2.0 in VS 2008. I run it as a console app to debug it.

Console app is working great. I put it on my local computer as a service, compiled in debug mode, still working great. I'm ready to release now, and suddenly, when I set it to release mode, the service compiles and installs, but nothing happens. (No code in service is running at all).

I realize that the release vs debug mode are property configuration settings, but it seems that in release mode, even when I check define DEBUG constant, uncheck Optimize code, and set Debug info to 'full', it is still doing nothing.

Set it back to debug and it's working like a charm again.

(As a sidenote, I tried resetting the target framework to 3.5 to make sure that wasn't the issue, too)

So my questions (in order of importance) are these:

  1. Will using my "debug" version in any way ever cause any problems?

  2. What settings are different between debug and release besides the three I've been trying to change already?

  3. This seems like a weird error to me and has stirred up my curiosity. Any idea what would cause this?

EDIT: Should mention, I already am using a custom installer. Basically I compile the program (in either debug or release) and then install it with the respective installer.

解决方案

1) It might, if not directly, so indirectly by making the application slower and making it use more memory.

2) When it runs in debug mode, there are certain things that works differently, for example:

  • The code is compiled with some extra NOP instructions, so that there is at least one instruction at the beginning of each code line, so that it will be possible to place a break point at any line.

  • The instructions can be rearranged in release mode, but not in debug mode, so that the code can be single stepped and the result will correspond to the exact order of the source code.

  • The garbage collector works differently, by letting references survive throughout their entire scope instead of only for the time that they are used, so that variables can be viewed in debug mode without going away before the scope ends.

  • Exceptions contain more information and takes a lot longer to process when thrown.

All those differences are relatively small, but they are actual differences and they may matter in some cases.

If you see a great difference in performance between debug mode and release mode, it's usually because there is something wrong with the code, like for example if it's throwing and catching a huge amount of exceptions. If there is a race condition in the code, it may only happen in release mode because there is some extra overhead in debug mode that makes the code run slightly slower.

3) As to what the problem with your service is, I don't know, but it doesn't seem to be related to how the code is executed in debug mode or release mode. The code would start in any case, and if it was a problem with the code, it would crash and you would be able to see it in the event log.

这篇关于Visual Studio-调试与发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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