Search code examples
visual-studio-2010.net-4.0xdt-transform

Change connection string in Windows Forms based on build configuration?


Similar to how you can have multiple Web.config's in ASP.NET, is it possible to have multiple App.config's depending on the build configuration?

I want to change my connection string, so if I am building configuration test, the connection string should be:

"Server=test;Initial Catalog=test..."

If I am building against test2, the connection string would be:

"Server=anotherserver; Initial Catalog=test2..."

Currently, I am doing it manually, so I would like to know how can I automate this?


Solution

  • Although they are not natively support, you can have XML transformations also for Windows Forms projects (App.config) and not just for Web Application projects.

    There is a VS addin that enables that support and although I never tried it, it would be what I would recommend for environments where you have VS installed since is authored by at least one Microsoft employee that I'm sure has deep knowledge on MSBuild, since he already authored a book on the subject.

    SlowCheetah - XML Transforms

    I don't know if SlowCheetah provides support for CI servers without VS installed so I'll also throw another solution based on inclusion of custom target files.

    Visual Studio App.config XML Transformation

    (shameless plug notice, I was the original author of the one above)