3

In my client application I sometimes connect to localhost:1242\SomeService.asmx and some other times it connects to someDomain:1242\SomeService.asmx. In other words there are times when I want to test locally and some other times remotely.

The default options that VS gives you are debug and release. I want to create custom ones in fact I have just created a new build configuration: enter image description here

Anyhow how can I know in code if I am using that configuration?

I will like to do something like:

if(Configuration.Type == ConfigTypes.Local)
    ConectionString = "localhost:1242:\SomeService.asmx";
else if (Configuration.Type == ConfigTypes.Remote1)
    ConectionString = "SomeDomain1:1242:\SomeService.asmx";
else if (Configuration.Type == ConfigTypes.Remote2)
    ConectionString = "SomeDifDomain:1242:\SomeService.asmx";

Also release mode tends to be more efficient? How will I specify those settings?

Tono Nam
  • 34,064
  • 78
  • 298
  • 470

1 Answers1

7

You could define conditional compilation symbols.
Project properties → Build tab → Conditional compilation symbols.
Define there different symbols for different configurations, for instance:

  • SRV_LOCAL in the "Local" configuration;
  • SRV_REMOTE1 in the "Remote1" configuration;
  • SRV_REMOTE2 in the "Remote2" configuration.

Then in the code:

#if SRV_LOCAL
    private const string SERVER = "localhost";
#elseif SRV_REMOTE1
    private const string SERVER = "SomeDomain1";
#elseif SRV_REMOTE2
    private const string SERVER = "SomeDifDomain";
#endif
Dmitry
  • 13,797
  • 6
  • 32
  • 48
  • Plus one thanks for the help! thats a solution I am just curios to see if the other option works. If its not possible I will accept this answer. – Tono Nam Sep 24 '15 at 19:19