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.