Need .NET code to execute only when in debug configuration

前端 未结 8 1160
闹比i
闹比i 2021-01-30 10:38

I have some code that access an API out on the web. One of the API\'s parameters allows me to let them know that I am testing.

I would like to only set this parameter in

8条回答
  •  自闭症患者
    2021-01-30 11:07

    yes, wrap the code in

    #if DEBUG
    // do debug only stuff 
    #else
    // do non DEBUG stuff
    #endif
    

    Google for "C# compilation symbols"

    Visual Studio automatically defines DEBUG when you are in the debug configuration. You can define any symbols you want (look at your project's properties, the build tab). Beware that abusing preprocessor directives is a bad idea, it can lead to code that is very difficult to read/maintain.

提交回复
热议问题