Search code examples
c#pragma

Pragma use in across dll


I have a main Program A which calls a dllB method.

dllB is build in release mode. Depending on which mode the Program A is build(Release/Debug) the result should be returned appropriately but it always returns "releaseMode".

So is there a way where i can reference dllB in release mode and depending on the main program preference(Release/Debug) get the result.

Program A---
main ()
{
  var dllbObj = new dllB();
  var response = dllObj.CallMethod();
 //Release mode should return "releaseMode" 
 //and debug mode should return "debugMode"
}

dll B---
public string CallMethod()
{
 string res;
#if DEBUG
            res = "debugMode";
#endif
            res = "releaseMode";

            return res;
}

Solution

  • There's no way to achieve this with pragmas, because they are baked into the assembly at compile-time. If the second assembly is compiled in Release mode, it doesn't contain any code that might have been placed in a DEBUG section.