在c#中确定程序员是通过IDE还是用户运行程序的最佳方法是什么?

odi*_*seh 28 c# winforms

在c#中确定程序员是通过IDE还是用户运行程序的最佳方法是什么?

Web*_*euw 35

if (System.Diagnostics.Debugger.IsAttached) {
    // You are debugging
}
Run Code Online (Sandbox Code Playgroud)


mku*_*kus 7

public static bool IsInVisualStudio
{
    get
    {
        bool inIDE = false;
        string[] args = System.Environment.GetCommandLineArgs();
        if (args != null && args.Length > 0)
        {
            string prgName = args[0].ToUpper();
            inIDE = prgName.EndsWith("VSHOST.EXE");
        }
        return inIDE;
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 没关系,但启用Visual Studio Hosting过程是一个可以关闭的选项. (6认同)