.net Visual Studio 中的调试和发布有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/367884/
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
What is the difference between Debug and Release in Visual Studio?
提问by Cornel
Possible duplicate Debug Visual Studio Release in .NET
What is the difference between Debug and Release in Visual Studio?
Visual Studio 中的调试和发布有什么区别?
回答by Vilx-
The most important thing is that in Debug mode there are no optimizations, while in Release mode there are optimizations. This is important because the compiler is very advanced and can do some pretty tricky low-level improving of your code. As a result some lines of your code might get left without any instructions at all, or some might get all mixed up. Step-by-step debugging would be impossible. Also, local variables are often optimized in mysterious ways, so Watches and QuickWatches often don't work because the variable is "optimized away". And there are multitudes of other optimizations too. Try debugging optimized .NET code sometime and you'll see.
最重要的是在 Debug 模式下没有优化,而在 Release 模式下有优化。这很重要,因为编译器非常先进,可以对代码进行一些非常棘手的低级改进。因此,您的代码的某些行可能根本没有任何说明,或者有些可能会混淆。逐步调试是不可能的。此外,局部变量通常以神秘的方式进行优化,因此 Watches 和 QuickWatches 通常不起作用,因为变量被“优化掉了”。还有许多其他优化。有时间尝试调试优化的 .NET 代码,你就会看到。
Another key difference is that because of this the default Release settings don't bother with generating extensive debug symbol information. That's the .PDB file you might have noticed and it allows the debugger to figure out which assembly instructions corresspond to which line of code, etc.
另一个关键区别在于,因此默认发布设置不会生成大量调试符号信息。那是您可能已经注意到的 .PDB 文件,它允许调试器找出哪些汇编指令对应于哪一行代码等。
回答by Joris Timmermans
"Debug" and "Release" are actually just two labels for a whole slew of settings that can affect your build and debugging.
“调试”和“发布”实际上只是可能影响构建和调试的一系列设置的两个标签。
In "Debug" mode you usually have the following:
在“调试”模式下,您通常具有以下内容:
- Program Debug Database files, which allow you to follow the execution of the program quite closely in the source during run-time.
- All optimizations turned off, which allows you to inspect the value of variables and trace into functions that might otherwise have been optimized away or in-lined
- A _DEBUG preprocessor definition that allows you to write code that acts differently in debug mode compared to release, for example to instrument ASSERTs that should only be used while debugging
- Linking to libraries that have also been compiled with debugging options on, which are usually not deployed to actual customers (for reasons of size and security)
- 程序调试数据库文件,允许您在运行时在源代码中非常密切地跟踪程序的执行。
- 关闭所有优化,这使您可以检查变量的值并跟踪可能已被优化或内联的函数
- _DEBUG 预处理器定义,允许您编写在调试模式下与发布时行为不同的代码,例如检测仅应在调试时使用的 ASSERT
- 链接到也已编译并启用调试选项的库,这些库通常不会部署到实际客户(出于大小和安全性原因)
In "Release" mode optimizations are turned on (though there are multiple options available) and the _DEBUG preprocessor definition is not defined. Usually you will still want to generate the PDB files though, because it's highly useful to be able to "debug" in release mode when things are running faster.
在“发布”模式下优化被打开(尽管有多个选项可用)并且未定义 _DEBUG 预处理器定义。通常,您仍然希望生成 PDB 文件,因为当事情运行得更快时,能够在发布模式下“调试”非常有用。
回答by Rik
Mostly, debug includes a lot of extra information useful when debugging. In release mode, this is all cut and traded for performance.
大多数情况下,调试包含许多在调试时有用的额外信息。在发布模式下,这一切都被削减并以性能换取。
回答by NeARAZ
If you go through project compile options and compare them, you'd see what are the differences.
如果您浏览项目编译选项并比较它们,您会看到有什么区别。
Assuming the question is about native/C++ code (it's not entirely clear from the phrasing):
假设问题是关于本机/C++ 代码的(从措辞中并不完全清楚):
Basically, in Debug all code generation optimizations are off. Some libraries (e.g. STL) default to stricter error checking (e.g. debug iterators). More debugging information is generated (e.g. for "Edit and Continue"). More things are generated in code to catch errors (local variable values are set to an uninitialized pattern, and the debug heap is used).
基本上,在 Debug 中,所有代码生成优化都已关闭。一些库(例如STL)默认进行更严格的错误检查(例如调试迭代器)。生成更多调试信息(例如“编辑并继续”)。在代码中生成了更多的东西来捕获错误(局部变量值设置为未初始化的模式,并使用调试堆)。
回答by annakata
It's probably worth mentioning the very obvious, that build flags allow for different logic which shouldbe used just to change logging and "console" messaging, but it canbe abused and dramatically change not just the low-levels, but the actual business logic.
可能值得一提的是,构建标志允许不同的逻辑,这些逻辑应该仅用于更改日志记录和“控制台”消息传递,但它可能会被滥用,不仅会显着改变低级别,还会显着改变实际业务逻辑。
回答by foraidt
Also note that when using MFCfor example, debug projects link against non-redistributable DLL versions like MFC90D.DLLwhile release builds link against the redistributable versions like MFC90.DLL.
This is probably similar to other frameworks.
另请注意,例如,在使用MFC时,调试项目链接到不可再MFC90D.DLL发行的DLL 版本,例如发布构建链接到可再发行版本,例如MFC90.DLL. 这可能与其他框架类似。
Therefore you will probably not be able to run debug-build applications on non-development machines.
因此,您可能无法在非开发机器上运行调试构建应用程序。
回答by Matt Jacobsen
回答by jxramos
I got curious on this question too when I had developed an application copied from an existing Release build configuration.
当我开发了一个从现有 Release 构建配置复制的应用程序时,我也对这个问题感到好奇。
I have a developer who is interesting in using that application in debug mode, so I wondered what it would take to make this build configuration that exists with a name of ReleaseMyBuild copied from a Release configuration (and thus should have all settings geared to release optimizations) to suddenly change teams and become a debug build despite the confusing build configuration name.
我有一个开发人员,他对在调试模式下使用该应用程序很感兴趣,所以我想知道如何制作这个名为 ReleaseMyBuild 的构建配置,它是从发布配置复制的(因此应该让所有设置都适合发布优化) 突然更换团队并成为调试版本,尽管构建配置名称令人困惑。
I figured the project configuration was just a name and a convenient way to select the "whole slew of settings" Joris Timmermans mentions. I wanted to know the nitty-gritty of just what those settings may be that make a build configuration named "FOO" function as an optimized releasebuild.
我认为项目配置只是一个名称,也是选择 Joris Timmermans 提到的“大量设置”的便捷方式。我想知道这些设置的本质是什么使名为“FOO”的构建配置功能成为优化的发布构建。
Here's one glimpse into it. I created a new VCXPROJ from the empty project template from Visual Studio 2010. I then copied it and edited both, the first to retain the debug contents and the second the release contents. Here's the diff centered upon the relevant differences...
这是一瞥。我从 Visual Studio 2010 的空项目模板创建了一个新的 VCXPROJ。然后我复制并编辑了它,第一个保留调试内容,第二个保留发布内容。这是以相关差异为中心的差异......
RELEASE
释放
<PropertyGroup>
<WholeProgramOptimization>true</WholeProgramOptimization>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
DEBUG
调试
<PropertyGroup>
<UseDebugLibraries>true</UseDebugLibraries>`
<ClCompile>
<Optimization>Disabled</Optimization>
It is interesting that in the Link section they both have GenerateDebugInformationset to true.
有趣的是,在 Link 部分,它们都GenerateDebugInformation设置为 true。
回答by fasih.rana
The obvious difference you can see is the size of the binary. A Debug build produces a larger binary than a Release build.
您可以看到的明显区别是二进制文件的大小。调试版本生成比发布版本更大的二进制文件。
When compiling in Debug, the symbol table is added to the compiled object of the code file which allows for debugging programs to tap into these binaries and access the values of objects and variables.
在 Debug 中编译时,符号表被添加到代码文件的编译对象中,允许调试程序访问这些二进制文件并访问对象和变量的值。
Another observable difference is that, in Release mode, the binary would simply crash on a fatal error while in Debug mode, if you start debugging the application in Visual Studio, you can check the call stack which tells you the exact location of the erroneous statement.
另一个明显的区别是,在发布模式下,二进制文件只会在调试模式下因致命错误而崩溃,如果您在 Visual Studio 中开始调试应用程序,您可以检查调用堆栈,它会告诉您错误语句的确切位置.
回答by f470071
I don't know what the exact differences are because there is actually no information easily available on that.
我不知道确切的区别是什么,因为实际上没有容易获得的信息。
But the main observed difference is that release version sometimes corrupts the resulting DLL file and thus makes you application, web application unusable.
但观察到的主要区别是发布版本有时会损坏生成的 DLL 文件,从而使您的应用程序、Web 应用程序无法使用。
Sadly, you have to put debug build in production. And yes, to publish you have to use good old FTP.
遗憾的是,您必须将调试版本投入生产。是的,要发布您必须使用良好的旧 FTP。


