In Visual Studio 2015 it was possible to check whether a running application had been started from Visual Studio by checking if a debugger is active and if the process was vshost.exe like this:
bool isInVisualStudio = Debugger.IsAttached && AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe");
Since Visual Studio 2017 this is no longer possible as the current domain is always the application executable name regardless of how it was started.
I have been trying without success to do the same thing in VS2019. The closest I can get is to check if a debugger is attached and if Visual Studio is running at the same time:
bool devEnvIsRunning = Process.GetProcessesByName("devenv").Length > 0;
bool isInVisualStudio = Debugger.IsAttached && devEnvIsRunning;
The problem with this for my purposes is that I want to skip some code when it is running from source in my copy of VS on my machine, but I definitely do NOT want to skip that code just because another debugger is installed.
I have been trying to find a way to get the name of the attached debugger which would solve the problem, but have been unable to do so.
Anyone got any suggestions on how to achieve in VS2019 that which was so easy in VS2015 and earlier?