Windows 8 应用程序正在调试

问题描述:

有没有办法检查 app.cs 是应用调试或部署的当前状态?

Is there a way to checkin app.cs is curent state of app debug or deployment?

或者问题是我只想在调试应用程序时执行一段代码.

Or the problem is that I want to exceute piece of code only when debuging application.

你可以像这样简单地使用 #if DEBUG 指令

You can simply use the #if DEBUG directive like so

#if DEBUG
    //code here only executes in debug
#endif

所以如果你想要一些在 DEBUG 中运行的代码和一些在 RELEASE 中运行的代码,你可以这样做:

So if you want some code that runs in DEBUG and some that is in RELEASE you do it like this:

#if DEBUG
    //code here only executes in debug
#else
    //code here only executes in release
#endif

正如 DAKL 已解释,您也可以使用 Conditional 属性.

And as DAKL has explained you could also use the Conditional attribute.