简体   繁体   English

C#调试和发布模式

[英]C# Debug and release mode

How to find whether it is in debug mode or release mode? 如何查找是处于调试模式还是发布模式? Are there any other ways to find it? 有没有其他方法可以找到它?

    #if(DEBUG)
{
       Console.WriteLine("Debug mode");
       //Or Things to do in debug mode
}
    #else
{
       Console.WriteLine("Release mode");
       //Or Things to do in Release mode- May be to change the text, image 
}
#endif

No that's the only way, but you need to have the syntax and capitalization correct. 不,这是唯一的方法,但你需要正确的语法和大小写。 You can also check whether the debugger is attached. 您还可以检查调试器是否已附加。 Here is the correct syntax: 这是正确的语法:

#if DEBUG
    Console.Writeline("debug");
#else
    Console.Writeline("release");
#endif
    // You can also check if a debugger is attached, which can happen in either debug or release
    if (Debugger.IsAttached)
        Console.WriteLine("debugger attached");

You could try using System.Diagnostics: 您可以尝试使用System.Diagnostics:

if (Debugger.IsAttached) {... ? if (Debugger.IsAttached) {...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发布模式下的C#mutex与调试模式下的行为不同 - C# mutex in release mode behaves different than in debug mode C#WPF应用程序在发布模式而不是调试模式下陷入困境 - C# WPF Application go haywire in Release Mode but not Debug Mode 检测DEBUG,RELEASE和我自己的模式C# - Detect DEBUG, RELEASE and my own mode C# Java是否具有像C#这样的“调试”和“发布”构建模式? - Does Java have 'Debug' and 'Release' build mode like C#? 在C#中,Debug.Assert测试是否在发布模式下运行? - In C#, is a Debug.Assert test run in release mode? 如何在调试时调试Debug.WriteLine()和在.NET / C#中以发布模式在Console.WriteLine()之间切换# - How to switch between Debug.WriteLine() at debug and Console.WriteLine() in release mode in .NET/C# C#Debug vs Release - C# Debug vs Release UWP 应用程序在 Visual Studio 调试模式下工作,但发布版本无法运行,缺少 DLL (C#) - UWP App works in Visual Studio debug mode, but the release build won't run, missing DLL (C#) 为什么代码在c#Interactive(Roslyn)和调试\\发布模式下的行为不同? - Why code behave different in c# Interactive (Roslyn) and in debug\release mode? .dll引用在调试模式下正确加载到c#项目中,但在Release中找不到名称空间 - .dll reference loads properly into c# project in Debug mode but can't find namespaces in Release
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM