1

I have certain features in my application that I only want available to me while I'm running my application through Visual Studio. Once I compile the application and distribute the standalone executable, I don't want those features exposed.

Is there a simple way to perform this check?

Michael Mankus
  • 4,628
  • 9
  • 37
  • 63
  • 2
    see this related question http://stackoverflow.com/questions/101806/check-if-application-was-started-from-within-visual-studio?rq=1 – Amitd May 15 '13 at 16:47
  • 4
    Have you considered adding the DEBUG attribute to what you don't want exposed? That should make it so when you build it in release they are removed. – DotNetRussell May 15 '13 at 16:47
  • Are you running "Start Debugging" or "Start without Debugging"? You can check for the first case with http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.isattached.aspx – kevingessner May 15 '13 at 16:47

1 Answers1

1

Can you just use #if DEBUG

#if DEBUG
    // Code for debug builds only
#endif

Then you distribute the release build and the debug code won't be there.

You don't have to use DEBUG, you can use your own symbol and create build configurations that have it set, and other configurations that don't.

The advantage of doing it this way is that that code won't even be in the build, so there's no possibility of someone using Reflector or somesuch to inspect that code.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276