简体   繁体   English

如何在Win 7 visual Studio 2012中的C#中禁用#if DEBUG

[英]how to disable #if DEBUG in C# at Win 7 visual studio 2012

I am working on C# in Win 7 visual studio 2012. 我正在Win 7 visual studio 2012中使用C#。

I have #if DEBUG and I want to disable them. 我有#if DEBUG ,我想禁用它们。 But, when I run C# in Visual Studio with "start without debugging", the #if DEBUG is still effective. 但是,当我在Visual Studio中使用“无需调试即可启动”运行C#时, #if DEBUG仍然有效。

Any help would be appreciated. 任何帮助,将不胜感激。


UPDATE 更新

When I build my code in release, the #if DEBUG code is still there even though they are nor executed ? 当我在发行版中构建代码时,即使#if DEBUG代码也没有执行,它们仍然存在? Do I need to remove them manually ? 我需要手动删除它们吗? I need to get them removed after release. 发布后,我需要将其删除。 Thanks ! 谢谢 !

将构建配置从Debug更改为Release。

I assume you're already building against the "Release" built profile so I'll explain how to unset the DEBUG constant for release. 我假设您已经针对“ Release”构建的配置文件进行了构建,因此我将说明如何取消设置DEBUG常量以进行发布。

Right-click on the project and in the Build section remove flag from "Define DEBUG constant". 右键单击项目,然后在“ 构建”部分中,从“定义DEBUG常量”中删除标志。 This flag should be removed only for the "Release" built profile and set for the "Debug" built profile. 仅应为“发布”构建的配置文件删除该标志,并为“调试”构建的配置文件设置该标志。

When you choose "Start without debug" you are not telling to built for release, but just to not attach the debugger to the process. 当您选择“不调试开始”时,您不是在告诉要为发布而构建,而只是不将调试器附加到进程中。

Those are 3 different but inter-related things: built profile (Debug/Release), starting with or without debugger attached to the process and setting/unsetting the "Define DEBUG/TRACE constant". 这是3种不同但相互关联的东西:内置配置文件(调试/发布),在进程中附加调试器或不附加调试器,以及设置/取消设置“定义DEBUG / TRACE常量”。

"Start without debugging" only means that VS will not attach the debugger to the running process; “无需调试即可启动” 表示VS将不会将调试器附加到正在运行的进程。 it doesn't change anything else. 它不会改变其他任何东西。 You're probably running using the Debug configuration - if you want to compile in Release, you should choose Release from the dropdown in the toolbar, where you should currently see a dropdown set to Debug. 您可能正在使用Debug配置运行-如果要在Release中进行编译,则应从工具栏的下拉列表中选择Release,该下拉列表当前应显示为Debug设置。

Visual Studio creates these configurations for your project to start, which control what preprocessor flags are set to, as well as a bunch of other configuration (how much optimization to use, etc.). Visual Studio为要启动的项目创建这些配置,这些配置控制将预处理器标志设置为什么,以及一堆其他配置(使用多少优化等)。 You can edit them if you want, or even create new ones. 您可以根据需要进行编辑,甚至可以创建新的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM