0

Had a quick question.

I created a new build configuration and added a pre processor directive/symbol called "TEST" to test something out.

I'm using web forms. When I do this in the .cs

var isTestSet = false

#if TEST
        isTestSet = true;
#else
        isTestSet = false;

and then in my ascx itself in the markup, I do a quick test:

<% if (isTestSet == true) 
     alert("test is set");
   else
     alert("test is not set");
%>

In my local development environment, this works perfectly. If I build the solution in TEST, it alerts that it's set. When I build it in something like debug mode or release mode, it alerts that it's not set. When I take this very same dll that I compiled, however, and deploy it to another environment, it always comes up as false (never seems to work).

Any thoughts? Do preprocessor directives get carried over from the DLLs in which they were built? Meaning as long as my dll was built using this new configuration that adds the symbol, then it should be set, no? Does anything else need to be carried over for this to work? I thought it was just the DLL.

Thanks!

NullHypothesis
  • 4,286
  • 6
  • 37
  • 79
  • Preprocessor directives are processed before it is compiled. Use a normal `if`, if you you need the condition to be tested at runtime. – wimh Oct 25 '15 at 18:08
  • True, but to confirm, if I select TEST, build the dll, and deploy, it should absolutely be set to use TEST, no? – NullHypothesis Oct 25 '15 at 18:49

1 Answers1

1

Most likely you are using wrong copy of DLL.

Conditional statement are evaluated at compile time and IL does not include branches that are "if-def" out. You can verify what actually contained in the compiled DLL by using any decompiler i.e. ILSpy or even ILDasm (if you can only use tools that come with .Net/VS).

Note that if you use conditional attributes than they are present in compiled code and calling methods annotated with them will be compiled according to projects that references your DLL (see how Debug.Trace are marked for example). See #if DEBUG vs. Conditional("DEBUG") for more info.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179