为什么我的“#undef TRACE”指令没有得到尊重? [英] Why is my "#undef TRACE" directive not being respected?
问题描述
我有一个引用DLL的.EXE项目。用于生成DLL的源代码(* .cs文件)具有以下编译器指示:
I have an .EXE project which references a DLL. The source code (*.cs file) that is used to generate the DLL has this compiler directed:
//#define TRACE
#undef TRACE
IOW,不仅是define编译器指令被注释掉了,而且还特别添加了否定的undef。
然而,即使使用DLL项目的新版本(使用undef代码)和引用该新版本的.EXE项目,我也会收到大量的这些错误信息。我尝试构建EXE项目:
类或命名空间名称'LogInfo'在类或名称空间'HUtilCE'中不存在(你是否遗漏了)汇编参考?)
出现这些代码的代码是这样的:
IOW, not only is the "define" compiler directive commented out, but the negating "undef" is specifically added.
Yet, even with a new build of the DLL project (with the "undef" code) and the .EXE project referencing that new build, I am getting tons of these err msgs when I try to build the EXE project:
The type or namespace name 'LogInfo' does not exist in the class or namespace 'HUtilCE' (are you missing an assembly reference?)
The code where these occur are like this:
#if TRACE
HUtilCE.LogInfo.Add2LogFile(string.Format(
"frmEntry.PrepareForPrinting() exception = {0}", ex.Message));
#endif
所以...为什么正在评估TRACE条件代码,当undef TRACE生效时?
注意:#if TRACE中的代码DLL项目中的块(适当地)添加了#undef TRACE代码,但是(在这种情况下不恰当但可能并不令人惊讶)#if TRACE书中的代码EXE项目不会显示为灰色。
So...why is the TRACE conditional code being evaluated, when the "undef TRACE" should be in force?
Note: The code within "#if TRACE" blocks in the DLL project are (appropriately) grayed out with the "#undef TRACE" code added, but (inappropriately but probably not surprising under the circumstances) the code within the "#if TRACE" books in the EXE project are not grayed out.
推荐答案
#undef
仅影响当前文件:MSDN说它必须出现在任何非指令性陈述之前: http://msdn.microsoft.com/en-us/library /wkxst87d.aspx [ ^ ]
所以在你的DLL项目中更改它不会影响你的EXE项目 - 它们是c完全分开编辑。如果您不想在EXE(或您的DLL)中使用它,那么创建一个新的解决方案配置,专门从属性中删除/ declare(通过取消选中Build选项卡中的定义TRACE常量) - 记住您需要每个项目的新配置!
#undef
only affects the current file: and MSDN says it must appear before any non-directive statements: http://msdn.microsoft.com/en-us/library/wkxst87d.aspx[^]
So changing it in your DLL project will not affect it in your EXE project - they are completely separate compilations. If you don't want it in your EXE (or your DLL) then create a new Solution Configuration that specifically removes the /declare from the properties (by unchecking the "Define TRACE constant" in the Build Tab) - remember that you will need a new configuration for each project!
这篇关于为什么我的“#undef TRACE”指令没有得到尊重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!