visual-studio Visual Studio - 调试与发布

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3143244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:10:30  来源:igfitidea点击:

Visual Studio - Debug vs Release

c#visual-studiowindows-servicespropertiesrelease

提问by Brandi

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

我在 VS 2008 中构建了一个面向 .NET 2.0 的 Windows 服务。我将它作为控制台应用程序运行来调试它。

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)

(作为旁注,我尝试将目标框架重置为 3.5 以确保这不是问题)

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?

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

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

  3. 这对我来说似乎是一个奇怪的错误,激起了我的好奇心。知道什么会导致这种情况吗?

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.

编辑:应该提到,我已经在使用自定义安装程序。基本上我编译程序(在调试或发布中),然后使用相应的安装程序安装它。

回答by Guffa

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

1)如果不是直接的,它可能会通过使应用程序变慢并使用更多内存来间接地进行。

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

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

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

  • 代码编译时使用了一些额外的 NOP 指令,因此每一行代码的开头至少有一条指令,这样就可以在任何一行放置断点。

  • 在发布模式下可以重新排列指令,但在调试模式下不能重新排列,这样代码就可以单步执行,结果将与源代码的确切顺序相对应。

  • 垃圾收集器的工作方式有所不同,它让引用在整个范围内持续存在,而不仅仅是在它们被使用的时间段内存在,因此可以在调试模式下查看变量,而不会在范围结束之前消失。

  • 异常包含更多信息,并且在抛出时需要更长的时间来处理。

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.

3)至于你的服务是什么问题,我不知道,但它似乎与代码在调试模式或发布模式下的执行方式无关。代码在任何情况下都会启动,如果代码有问题,它就会崩溃,您将能够在事件日志中看到它。

回答by Chad

I'm not sure I can speak to #1 or #2, but when I've had problems like that, it was because of incorrect threading/concurrency. I'm not sure how large your app is, but that might be a good place to start.

我不确定我可以与 #1 或 #2 交谈,但是当我遇到这样的问题时,那是因为threading/concurrency 不正确。我不确定您的应用程序有多大,但这可能是一个不错的起点。