0

Note: I've searched for this on Google and didn't directly find anything related to WinForms. The suggested questions while typing this question didn't apply to my situation.

I have a WinForms (.NET 3.5) application that can be published/deployed to three different locations: development, test and production. Each deployment type has its own specific settings, for example: connectionString, title(s), webservice address, directories/files to read or other settings.

The current situation in the app.config is as following:

<!-- dev-->
<configuration>
  <configSections>...</configSections>
  <appSettings>
    <add key="Deployment" value="dev" />
    <add key="SourceDir" value="\\server\foo\dev" />
  </appSettings>
...
</configuration>

<!-- test -->
<configuration>
  <configSections>...</configSections>
  <appSettings>
    <add key="Deployment" value="test" />
    <add key="SourceDir" value="\\server\foo\test" />
  </appSettings>
...
</configuration>

<!-- prod -->
<configuration>
  <configSections>...</configSections>
  <appSettings>
    <add key="Deployment" value="prod" />
    <add key="SourceDir" value="\\server\foo\prod" />
  </appSettings>
...
</configuration>

And everytime the app needs to be published/deployed to a certain location, the other two are commented out. So if I build a DEV-release, I comment out the PROD and TEST sections. When publishing for production, ... you get the idea.

This is a useless time-consuming work. My question is: is there a way to avoid this? A way that I still have the separate deployment-specific configuration, but that I don't need to comment (out) the needed sections.

Abbas
  • 14,186
  • 6
  • 41
  • 72
  • 1
    You want to use config transformation... Works out of the box on web applications but not so much for WinForms. Check here for help on WinForms: http://stackoverflow.com/questions/3004210/app-config-transformation-for-projects-which-are-not-web-projects-in-visual-stud – Belogix Aug 12 '14 at 09:50
  • Are you updating the config every time you do a deploy? Is it changing? Normally, I deploy everything except the config, and only update it when there is something new or modified in it. – user1666620 Aug 12 '14 at 09:51
  • 1
    Look at using [SlowCheetah](http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5) for transforming app.config files. – DavidG Aug 12 '14 at 09:52

0 Answers0