0

Possible Duplicate:
#if Not Debug in c#?

I am not have the permission to upload to the server so I am not able to test the #else part. I was wondering if this is the ideal way to have conditionally choose what drive letter to use depending on if in DEBUG (test mode) or in Production mode (#else part)

    #if (DEBUG)
     string driveLetter = "C:\\";
    #else
      string driveLetter = ConfigurationManager.AppSettings["ProdDrive"]; 
    #endif
Community
  • 1
  • 1
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
  • 1
    When you are picking the drive from configuration file, I do not see any need of the Debug flag. You just need to modify the configuration files in development and production mode. – Deepansh Gupta Jan 02 '13 at 16:44
  • 2
    Why not just use only configuration? ie. why not just configure the test builds with C:\? – Kent Boogaart Jan 02 '13 at 16:44
  • Think about the complexity you're going to impose in your code when you have a large number of app settings! Scott Hanselman had a good writeup of managing config files via Visual Studio Configuration Manager: http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx – Reacher Gilt Jan 02 '13 at 16:55

4 Answers4

1

As an alternative, consider since you are using a config file, just modifying the config file depending on debug or not. While debug versions are not often deployed in a production environment they can be to track down otherwise non-reporoducable issues.

Mike Beeler
  • 4,081
  • 2
  • 29
  • 44
0

Yes you can.

Here is some sample code I pulled from this msdn link:

// preprocessor_if.cs
#define DEBUG 
#define MYTEST
using System;
public class MyClass 
{
    static void Main() 
    {
#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
    }
}
Ben Tidman
  • 2,129
  • 17
  • 30
0

You can add this code

#define ANOTHERVALUE

Note : Delete #define DEBUG

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
0

Extending the answer from @Mike.Beeler I strongly suggest that you use Slow Cheetah for this. Slow Cheetah provides XML transforms to any XML (including .config) file for your project based on the current build configuration.

The most common use is to automatically set the correct DB connection string, but you can also use it to set an app setting.

It is a free VS extension from a Microsoft employee

http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

Eric J.
  • 147,927
  • 63
  • 340
  • 553