7

We have a development database and a production database. What I am trying to prevent is having to change:

connectionString="Data Source=server;Initial Catalog=test;
connectionString="Data Source=server;Initial Catalog=live;

We have two places we deploy the site. One for testing and one is live.

Is there an easy way to prevent us from having to change the connection string every time we want to upload to test or live?

We use team foundation server, I have no idea how to set up a build server or build definitions so looking for something simple if there is anything.

James Wilson
  • 5,074
  • 16
  • 63
  • 122
  • Are these in your web.config? http://msdn.microsoft.com/en-us/library/dd465326.aspx – cadrell0 Jul 29 '13 at 16:52
  • I use slow cheetah for this and works wonders. See here:http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5 – Icarus Jul 29 '13 at 16:53
  • I would first address the fact you need a build server: http://stackoverflow.com/questions/616149/how-and-why-do-i-set-up-a-c-sharp-build-machine once you do you can address your question any number of ways. – Security Hound Jul 29 '13 at 16:56
  • @cadrell0 yes they are. – James Wilson Jul 29 '13 at 17:02
  • @Ramhound I agree, but I looked into setting up a build server, build client, build definitions and it just all seemed above me at the moment. – James Wilson Jul 29 '13 at 17:04
  • @JamesWilson - So do some more research until its not above you. Your response seems like an excuse. – Security Hound Jul 29 '13 at 17:07
  • @Ramhound Setting up a build server, while a good idea, is not required just to do some simple web.config transformations. – cadrell0 Jul 29 '13 at 17:10
  • @Ramhound or I could have deadlines that would prevent that solutions from being practical at this time. That solution is not possible due to time constraints, however down the road it will be an option. – James Wilson Jul 29 '13 at 17:22

3 Answers3

6

If you're developing an ASP.NET application you can use web.config transforms to easily specify what will be different between each environment. The build process will generate an appropriate web.config for whatever environment you're targeting.

If you're building a desktop application, I'd look into Slow Cheetah which allows you to use the same web.config transform feature on any xml file you like, including an app.config. We've used this on a number of the projects at my company to streamline the deployment process between our various environments.

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
  • I setup the seperate Web.Debug.config and Web.Release.config with the differences in the connection strings. But when I change it from debug/release it still seems to leave the original web.config with my live version. And when I run the application with debug/release it uses the live version. What am I missing? – James Wilson Jul 29 '13 at 17:18
  • @JamesWilson If you're using the Visual Studio debugger, I believe it will always use the default `web.config` without any transformation. It will apply the transform only once you go to deploy it. – p.s.w.g Jul 29 '13 at 17:22
3

You can use web.config.release to mention your release mode configurations. These are part of VS2010 and above. You can get a very good look at Scott Hanselman article here.

A thing to note here is that transformation from debug to release will take place whenever you publish your web site before deploying.

Ehsan
  • 31,833
  • 6
  • 56
  • 65
1

Find a good tutorial for setting up a Continuous Integration build. The newer versions of TFS handles it really well.

It is a lot to get to grips with, but so worth the effort. Try the MSDN articles for it, go for all the default options, and it won't be that bad.

Get CI up and running, and you'll know what to do with these web.config transforms (which will solve your immediate problem). But by going through the process of setting up builds you'll find deployments so much easier.

Jamie Burns
  • 1,258
  • 9
  • 21
  • I agree that will be a path I take hopefully soon down the road. Reading over what it offers makes me want to do it now, I just can't meet the deadline and this. So I need a cheap and dirty now and then a good solution down the road. ;) – James Wilson Jul 29 '13 at 17:23
  • Oh I know that feeling! Good luck with it. – Jamie Burns Jul 29 '13 at 18:42