How to detect that C# Windows Forms code is executed within Visual Studio?

后端 未结 8 1931
春和景丽
春和景丽 2020-11-29 23:46

Is there a variable or a preprocessor constant that allows to know that the code is executed within the context of Visual Studio?

8条回答
  •  青春惊慌失措
    2020-11-30 00:13

    I think the simplest and most reliable way to determine if your extension is executed in the WinForms designer is to check the current process.

    public static bool InVisualStudio() {
      return StringComparer.OrdinalIgnoreCase.Equals(
        "devenv", 
        Process.CurrentProcess.ProcessName);
    }
    

提交回复
热议问题