条件调试 - 它是否仍然编译成发布代码?
我知道,如果我将代码标记为 DEBUG 代码,它不会在 RELEASE 模式下运行,但它仍然会被编译成程序集吗?我只是想确保我的程序集不会因额外的方法而变得臃肿。
[Conditional(DEBUG)]
private void DoSomeLocalDebugging()
{
//debugging
}
I know that if I mark code as DEBUG code it won't run in RELEASE mode, but does it still get compiled into an assembly? I just wanna make sure my assembly isn't bloated by extra methods.
[Conditional(DEBUG)]
private void DoSomeLocalDebugging()
{
//debugging
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,无论您如何编译,方法本身仍然被构建。
这是完全合乎逻辑的 - 因为
Conditional
的要点是依赖于调用者构建时定义的预处理器符号,而不是被调用者构建时定义的预处理器符号。建造的。简单测试 - 构建这个:
运行代码(不定义 FOO),您将看到没有输出,但如果您查看 Reflector,您将看到该方法仍然存在。
换句话说:您认为 .NET 已发布的程序集(我们编译的程序集)是使用定义的 DEBUG 符号构建的吗?如果它们不是(我强烈怀疑它们不是!)我们如何能够调用 Debug.Assert 等?
诚然,当您构建私有方法时,不包含它是有意义的 - 但正如您所看到的,它仍然被构建 - 这对于简单性和一致性来说是合理的。
Yes, the method itself still is built however you compile.
This is entirely logical - because the point of
Conditional
is to depend on the preprocessor symbols defined when the caller is built, not when the callee is built.Simple test - build this:
Run the code (without defining FOO) and you'll see there's no output, but if you look in Reflector you'll see the method is still there.
To put it another way: do you think the .NET released assemblies (the ones we compile against) are built with the DEBUG symbol defined? If they're not (and I strongly suspect they're not!) how would we be able to call
Debug.Assert
etc?Admittedly when you're building private methods it would make sense not to include it - but as you can see, it still is built - which is reasonable for simplicity and consistency.