问题
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