VS2013 Automatically comment line of code while build/debug

懵懂的女人 提交于 2019-12-25 05:36:11

问题


I try to find something that could help me but nothing was good so far.

I would like to know if there is any option to comment some lines of code while i start building/debugging?

I don't want to do it manually ("edit and continue" manually isn't a solution). I want "tell VS" to automatically comment specified line of code if i start to build or debug.
I need this line of code when i am testing app at server, but when i do it locally i have to have it commented. Hope you understand my problem and will give me fast solution, thank you.

I use VS2013 and C#.


回答1:


Would preprocessor directives help you? By default the DEBUG directive is enabled for Debug configurations, so any code between #if(DEBUG) and #endif will only be executed in your Debug configuration.




回答2:


One possibility:

if( !System.Diagnostics.Debugger.IsAttached )
{
  //code which should only run if not being debugged
}

Otherwise use preprocessor directives as Jenszcz suggests.



来源:https://stackoverflow.com/questions/31670779/vs2013-automatically-comment-line-of-code-while-build-debug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!