How can I tell if an application is running as a post/pre-build event or standalone?

447 views Asked by At

I have an application that is being run as a post-build event:

Project Properties -> Build Events: call "$(TargetDir)\bin\myApp.exe" "$(ProjectPath)"

However, sometimes I will run it by itself - sometimes from Visual Studio and sometimes straight from the console.

How can I tell programmatically if an application is being run as a post/pre-build event or standalone (so sometimes there will still be debugger attached, but not always)?

Is there some kind of flag or environment variable I can check?

Note: I want to check this from within the application that is being run.

1

There are 1 answers

1
Daniel On

The following will tell you if the debugger is attached.

if(System.Diagnostics.Debugger.IsAttached)
{
    // ...
}