Windows 8 app is debug

帅比萌擦擦* 提交于 2019-12-13 04:53:44

问题


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.


回答1:


You can simply use the #if DEBUG directive like so

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

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

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




回答2:


You can use [ConditionalAttribute("DEBUG")] for that.

If you want a method only to be executed in debug mode you can do the following:

[ConditionalAttribute("DEBUG")]
public void WriteOnlyInDebug(string message)
{
    Console.WriteLine(message);
}

This method is only called in Debug mode. The method and all calls to it are getting removed from the binary when you build your app in release mode.




回答3:


The other answers tell you how to check at runtime if your app is compiled as a Debug build. If you're wanting to see if Visual Studio (or any other debugger) is attached and debugging your app you can use System.Diagnostics.Debugger.IsAttached.



来源:https://stackoverflow.com/questions/12693274/windows-8-app-is-debug

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