c# - 如何分辨 "if on development environment"?

标签 c# visual-studio

我想为我在 Visual Studio 中开发的 C# 程序添加一个条件:

#If onEditor 
   do something

在 Unity 中存在 if Application.isEditor

Visual Studio 上的“常规”(WinForms 或 ASP.NET)C# 应用程序中是否存在某些内容?

最佳答案

#if 是编译指令,因此无论发生什么,都将在编译时进行检查,而不是在运行时进行检查。 #if DEBUG 这实际上意味着“这是在 Debug模式下构建的”,而不是“ Release模式”。如果您的程序运行,它不会说明任何有关起源的信息。

我想你要找的是Debugger.IsAttached :它检查是否附加了调试器。如果它是 true,则程序要么从 Visual Studio 运行,要么稍后附加调试器。

关于c# - 如何分辨 "if on development environment"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58075144/

相关文章:

c# - 使用 Microsoft Interop 读取和写入 excel 单元格

c# - 使用多级嵌套反序列化 JSON

c# - 无法连接到 PayPal 沙盒以验证 IPN 监听器收到的消息

c++ - 在 Visual Studio 2010 中编译单个 C++ 文件

c# - 框架约定的静态检查

html - 当我在 visual studio 上运行我的 Angular 应用程序时出现错误。

c# - 如何在 GTK# 中使用 Ubuntu Unity 全局菜单?

c# - 如何获取每个用户的第一行和最后一行数据

visual-studio - 使用 Template10 在 UWP 应用中测试暂停/恢复

c# - 为 webClient.DownloadFile() 设置超时