0

I have code that tests which folder a project is running from to determine if it is the testing version or production version. I know there is a way to do this with the difference between debug version and released (which I want to do in the future but I don't know how yet). So for now, this is a workaround to get me what I need. This code works correctly when I run from Visual Studio but not when my scheduled task runs the compiled version.

string projectPath = System.IO.Directory.GetCurrentDirectory();
var TestVersion = true;
if (projectPath == @"H:\Automation\RefreshData\RefreshData\bin\Debug" || projectPath == @"\\atlelz1fs03.atalanta.local\USERS\Automation\RefreshData\RefreshData\bin\Debug" || projectPath == @"H:\Automation\RefreshData" || projectPath == @"\\atlelz1fs03.atalanta.local\USERS\Automation\RefreshData")
{
    TestVersion = false;
}

Which folder should I be looking at for the compiled version? or is there a better way for me to determine this?

Liam
  • 27,717
  • 28
  • 128
  • 190
djblois
  • 963
  • 1
  • 17
  • 52
  • Why don't you just display `projectPath` so you can see? – itsme86 Mar 30 '17 at 14:35
  • Use `#if DEBUG` instead. [Details here](http://stackoverflow.com/questions/3788605/if-debug-vs-conditionaldebug) – Liam Mar 30 '17 at 14:36
  • 3
    *Which folder should I be looking at for the compiled version* well that depends on where you put the compiled version! That's basically why this is a bad idea in a nut shell – Liam Mar 30 '17 at 14:37

1 Answers1

3

Use precompiler statements:

#if DEBUG
    var TestVersion = true;
#endif
#if !DEBUG
    var TestVersion = false;
#endif

then when in debug mode run with debug selected in visual studio (as normal) when you release this change it to Release:

enter image description here

this will set TestVersion to false in your released code only. (BTW I have lots of configuration options, just ignore these, you will likely have Debug and Release only)

This works even better if you use continuous integration to compile your code for you, you can then configure this to do this, so you don't forget.

Liam
  • 27,717
  • 28
  • 128
  • 190
  • Liam how do I define DEBUG? I just tried this method but I used #else instead and it still came up as TestVersion true. – djblois Mar 30 '17 at 16:15
  • DEBUG is a built in variable in the precompiler. It means the DEBUG flag is set on the assembly. It doesn't show up in intelliense, etc. just type it exactly as above – Liam Mar 30 '17 at 16:18
  • It is not working for me :( I will put the issue in my original post – djblois Mar 30 '17 at 16:21
  • Never Mind I figured it out – djblois Mar 30 '17 at 16:22