为什么我要使用 .NET 编译器的调试模式?
我很好奇 .NET 编译器的调试模式和发布模式之间有什么区别,并遇到了有关 .NET 中的调试与发布 和 发布的行为与调试不同的原因。 到目前为止,我还没有真正关注这些编译器模式。 现在我会的。
我的问题是,假设我使用测试框架(NUnit)和 TDD,如果我总是在发布模式下编译,我会遇到任何问题吗?
I was curious what the differences are between the debug and release modes of the .NET compiler and came across these questions about debug vs release in .NET and reasons that release will behave differently than debug. Up to this point I really haven't paid much attention to these compiler modes. Now I will.
My question is, assuming that I am using a testing framework (NUnit) and TDD, would I run into any issues if I simply always compiled in release mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在使用 TDD。 你写你的测试。 测试失败。 您编写代码以通过测试。 代码失败。 您查看自己编写的代码,看不到任何明显的失败原因。 您是否会进行更多推理或在调试器中启动测试(使用 TestDriven.Net)并逐步完成测试? 也许我只是不够聪明,无法总是弄清楚为什么我的代码不起作用,但当我遇到困难时,我通常会选择后者。
You're using TDD. You write your test. The test fails. You write the code to pass the test. The code fails. You look at the code you wrote and can't see any obvious reason why it fails. Do you reason some more or start up the test in the debugger (using TestDriven.Net) and step through the test? Maybe I'm just not smart enough to always figure out why my code doesn't work, but I usually do the latter when I'm stumped.
调试模式关闭了很多优化。 这意味着当您获得堆栈跟踪时,它将看起来更像原始代码。
Debug mode turns off a lot of the optimizations. This means when you get a stack trace it will look more like the original code.
调试和发布配置之间的一个非常显着的区别是,只有在定义了关联符号的情况下,才会编译对用
ConditionalAttribute
标记的方法的调用。 因此,如果您使用发布配置进行编译,则不会包含对 Debug 类方法的调用。这使您可以使用断言和将信息转储到控制台的代码来装饰您的代码,并且确信这些开销不会出现在您的运输代码中。
此外,编辑并继续是一个非常有用的工具,它依赖于发布版本中省略的元信息。
A pretty significant difference between the debug and release configurations is that calls to methods marked with
ConditionalAttribute
are only compiled if the associated symbol is defined. So your calls to methods of theDebug
class don't get included if you compile using the release configuration.This lets you festoon your code with assertions and code that dumps information to the console, and yet be confident that none of that overhead's going to appear in your shipping code.
Also, edit-and-continue is an extremely useful tool, and it relies on metainformation that's omitted from release builds.
用于调试。
就像 tvanfosson 所说,即使您通常不使用调试器(我知道我不使用),有时您也需要这样做。
For debugging.
Like tvanfosson said, even if you usually don't use the debugger (I know I don't), sometimes you need to.