views:

72

answers:

3

I have a client side app (WPF) that hits my web services.

When I am running in dev I want to hit the Dev version of these web services. When I am running in the Test environment I want to hit the test version of the services. Like wise for production.

Since these values are in my app.config file what is the best way to switch between them?

A: 

Are you wanting to switch when you build the app? NAnt may be a way to handle this, or using options within Visual Studio possibly as there is a debug and release build modes.

For the few times I've had to do something similar, I prefer tweaking the hosts file on the client machine so that I can use the same DNS for dev,test and production. I'm not sure if that is practical or not in your case.

JB King
A: 

I typically maintain 3 separate config files and manually switch them when I install. Scott Hanselman has an article on how to use the build modes along with pre-build events to automatically switch between various configurations. Investigating this as an alternative is on my list of things to do so I can't tell you how well it works in practice.

tvanfosson
+1  A: 

Another single config file way would be to do something along the lines of:

<add key="Service-DEV" value="serviceUrl"/>
<add key="Service-UAT" value="serviceUrl"/>
<add key="Service-PROD" value="serviceUrl"/>

If your app knows which environment it's running in you could then just pull which one you need.

Up to you though. I've also used the multiple config approach with deployment scripts that deploy the correct file to the requested deployable environment.

Joshua Cauble