0

I have a project that compiles in to an .exe This project needs to be available in 2 editions. Everytime I perform an update, I need to comment out several pieces for "edition A" and vica versa for "edition B".

The reason for "(un)commenting" instead of just using a config setting or some context variable is because I don't want Intermediate Code from "Edition A" to be available in "Edition B" and vica versa because this would make the life of software crackers a lot more easy.

Is there a way in visual studio to add/remove code from compilation based on a setting?

Thank you !

user1841243
  • 1,663
  • 2
  • 19
  • 35

2 Answers2

1

Maybe you need Preprocessor Directives:

#define PI 
using System;
namespace PreprocessorDAppl
{
   class Program
   {
      static void Main(string[] args)
      {
         #if (PI)
            Console.WriteLine("PI is defined");
         #else
            Console.WriteLine("PI is not defined");
         #endif
         Console.ReadKey();
      }
   }
}
Darkwing
  • 314
  • 9
  • 24
  • Thanks for your response. Looks like this is something to be performed per File if I'm correct? Thumbs up. See my answer to see what I've done. Regards, – user1841243 May 27 '15 at 07:33
1

Based on this SO post I found the answer to my question:

#if debug --> #if myOwnConfig?

FIRST:

1.Build -> Configuration manager -> Active solution configuration -> New...

2.Create a new configuration "Offline".

3.Project -> Properties -> Build -> Configuration -> Offline

4.Conditional compilation symbols: type OFFLINE

5.Save project.

THEN , right click your project

1.go to Properties -> Build.

2.At the configuration dropdown, select "Offline"

3.Add "OFFLINE" to the "Conditional compilation symbols" text box

Result:

#if Offile
        MessageBox.Show("Offline");
#endif

#if NotOffline
        MessageBox.Show("NotOffline");
#endif
Community
  • 1
  • 1
user1841243
  • 1,663
  • 2
  • 19
  • 35