Question

I have created a console application responsible for generating exports of data from a database. This has to be deployed to a batch server which is different than where the database is running. In the app.config I need to configure the connectionstring to the database. I am having about eight environments where I need to deploy this console application. Upto now I needed to store the original configuration file for each environment and copy it separately to the installation folder.

The first thing I know was adding the files to the setup project in Visual Studio. Next to the primary output I have added all configuration files with a condition property on them. I added a screen to the setup wizard (textbox) where I ask the user installing to enter the environment name as I have specified. I got this configured succesfully in one of the setup projects, but in two projects my solution is not correct. In those I always end up with my app.config file in the installation folder and not with the configuration file I have created in the setup project. When I rename the files, I only see them when I enter the correct details during setup. So my guess is that my files are somehow overwritten with the app.config from my project.

The build result of my setup:

Building file 'C:\MyProject\MyProject.Setup\Deploy\MyProject.msi'...
Packaging file 'MyProject.exe.config'...
Packaging file 'MyProject.exe'...
Packaging file 'MyProject.exe.config'...
Packaging file 'MyProject.exe.config'...

Does anyone know what is failing here? Do I need special conditions or settings? Or maybe another deployment stragegy. Manually editing the configuration files is not an option. I appreciate all help. Thanks in advance.

Was it helpful?

Solution

If it is only about the connection string, add a reference to a second config file which you deploy to your folder, like:

<connectionStrings configSource="connectionstrings.config" />

Or deploy your complete config file seperately, and load it in your application like:

var map = new ExeConfigurationFileMap {ExeConfigFilename = @"C:\MyProject\custom.config"};
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top