c# - DEBUG 与 RELEASE 和分发程序集

标签 c# .net conditional-compilation

我正在创建和分发供其他开发人员使用的程序集。 我正在分发我的程序集的发布版本(不是调试)。 在我的程序集的一个类中,我将代码设置为仅在 Debug模式下使用

#if DEBUG
    Console.WriteLine("Debug");
#else
    Console.WriteLine("Release");
#endif

如果其他开发人员从他们的项目中引用我的程序集并在 Debug 模式下运行他们的项目,我的 Debug only 是否会条件运行?

最佳答案

If other developers reference my Assembly from their project and run their project in Debug mode, will my Debug only conditional run or not ?

不,因为 Console.WriteLine() 由于预处理器约束从未在 Release 模式下编译。

MSDN 对此有更多说法:

When the C# compiler encounters an #if directive, followed eventually by an #endif directive, it will compile the code between the directives only if the specified symbol is defined ... Tell me more...

此外,认为它已从程序集中删除是不正确的,因为它从来没有出现过。

关于c# - DEBUG 与 RELEASE 和分发程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41442036/

相关文章:

c# - 通过 OracleDataReader 读取时处理 NULL 值?

c# - VS2019 中的测试资源管理器显示 "No source available"用于规范流测试

基于操作系统版本的 C# 条件编译变量

c# - C#创建线程的方法

c# - 如何在 C# 中为窗口添加滚动条

c# - PLSQL Oracle Command不允许在同一个命令中出现多个异常

android - .NET 中的加密和 Android 中的解密抛出 BadPaddingException : pad block corrupted

无法解析条件编译 block 内的类函数宏

gcc - 在编译时确定 LLVM 与 GCC

c# - 通过 SqlConnection/SqlCeConnection 连接到 .sdf 数据库时出现问题