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

后端 未结 8 1920
春和景丽
春和景丽 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:34

    I use this code to distinguish whether it's running in Visual Studio or if it's deployed to customers.

    if (ApplicationDeployment.IsNetworkDeployed) {
        // do stuff 
    } else {
       // do stuff (within Visual Studio)
    }
    

    Works fine for me for ages. I skip some logic when inside Visual Studio (such as logging in to application etc).

    0 讨论(0)
  • 2020-11-30 00:35

    You can use this:

    protected static bool IsInDesigner
    {
        get { return (Assembly.GetEntryAssembly() == null); }
    }
    
    0 讨论(0)
提交回复
热议问题