Question

I use some COM libraries in my code. Their are depending by the target platform (x86\x64). So I need build my project separately x86 and x64 too. Every time when I switch the target platform (x86\x64) in my project settings, I add or remove manually the "PLATFORM_X86" value also into the "Conditional Compilation Symbols" (the "Build" tab).

#if PLATFORM_X86
    customTableStyle.SetTextStyleId(cellStyle_1,
      textStyleId.OldIdPtr.ToInt32());
#else
    customTableStyle.SetTextStyleId(cellStyle_1,
      textStyleId.OldIdPtr.ToInt64());
#endif // #if PLATFORM_X86

Can I solve it more "clear", without add\remove the "PLATFORM_X86" manually every time? Are exist the "built-in" symbol which are pointing the current platform? If "yes" what its name?

Was it helpful?

Solution

First of all, create two separated solutions configurations: from within Build -> Configuration Manager select drop down Active solution configuration and select , then you can set Conditional compilation symbols in project settings for each of those configuration separately.

Then you can use Conditional attribute on classess or methods:

[Conditional("DEBUG")]
public void Method()
{

}

Here is an example from MSDN:

#define DEBUG
using System;
using System.Diagnostics;
class Class1 
{
   [Conditional("DEBUG")]
   public static void M() {
      Console.WriteLine("Executed Class1.M");
   }
}
class Class2
{
   public static void Test() {
      Class1.M();
   }
}

This declares Class1.M as a conditional method. Class2's Test method calls this method. Since the conditional compilation symbol DEBUG is defined, if Class2.Test is called, it will call M. If the symbol DEBUG had not been defined, then Class2.Test would not call Class1.M.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top