Search code examples
visual-studiovisual-studio-2013projects-and-solutions

Keep different versions of one program - Visual Studio


I have a program. There are two versions of it, one has two lines commented out. I would probably do the same improvements to both codes, so in the end the difference will be the same two lines.

Now, I need an easy way to manage both. Currently, I have both in one project and I keep commenting and uncommenting the lines for each build. So, I have two possible solutions:

  • Keep two projects. This will be very unproductive. I need to do the same improvements to both projects.
  • Have a settings value. (e.g. a bool named isClient1) This is simple and good, I would set it to true or false when I'm building it, however it's no different from what I'm doing right now. Setting a value to true or false doesn't seem to be any easier than commenting/uncommenting two lines.

Is there an ideal way? (Visual Studio 2013)


Solution

  • You can try conditional compilation. With conditional compilation you can create a new "configuration" in your project such as "release2" and then specify a symbol for that configuration so that when "release2" is selected then those two lines will be commented or uncommented.

    Take a look at this example here: http://pinter.org/?p=1060