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?

4
  • can you use config transforms and an app.config file? Commented Sep 24, 2015 at 19:07
  • Can you use different conditional compilation constants? Commented Sep 24, 2015 at 19:08
  • Never tried. Yes I can. I am just curios on how to make this work because it will be very easy and convenient to change configurations by just changing a drop down instead of having to go to the app.config file. Commented Sep 24, 2015 at 19:08
  • yes its a build time process. theres plenty of resources on them. Commented Sep 24, 2015 at 19:09

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.