Reputation: 1713
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 !
Upvotes: 0
Views: 70
Reputation: 1713
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
Upvotes: 1
Reputation: 314
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();
}
}
}
Upvotes: 1