views:

31

answers:

1

I have a WPF windows application that makes a call to a DLL for registration. I need this code to be called only when the application is run outside of visual studio. In other words, when clicking run from within the visual studio, I dont want this code executed but want it executed if EXE is called outside of visual studio.

Is there a way where I can do that withouht having to keep commenting and uncommenting this code?

+4  A: 

you could use the preprocessor:

#if DEBUG
   code to run during debug mode only
#else
   normal code
#endif

or the Conditional attribute

[Conditional("DEBUG")]
private void SomeMethod()
{
 stuff
}
Causas
Sidenote: I would recommend the conditional attribute, as using the preprocesser doesn't play well with intellisense.
Causas
This is a solution - but you should mention that you should compile with DEBUG mode - both solutions do not check if you are within Visual Studio! Only if the code is compiled with DEBUG mode.
Andreas Rehm