I'm working on a setup project. In a separate library project I created a custom installer by inheriting from System.Configuration.Install.Installer and added the generated .dll as a custom action.(Install step). I added an app.config file to the library project where I store a connection string which I need to make a connection to Sql Server.
Once I run the setup project, the custom installer doesn’t retrieve the connectionString stored in the app.config file.
Where can I store the connection string? Can a setup project have an app.config? Could somebody recommend a book on deployment/setup projects?
Thanks
UPDATE
Hi,
Thanks. Based on the replies I've updated my code this is what I´m doing now:
-> In setup project, I added a custom action to the install step, selecting application folder and primary output(library project).
-> Added an app.config to the library project and set its build action to "content".
-> Added the library project content files to the setup project.
This way the app.config file appears in the install folder.
Within the install handler from my custom install class I do the following: (in this case I access the application settings)
string appPath = "";
appPath = Path.Combine(new DirectoryInfo(Context.Parameters["assemblypath"].ToString()).Parent.FullName, "App.config");
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = appPath;
System.Configuration.Configuration c = null;
c = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
string result = c.AppSettings.Settings["test"].Value;
Best Answer
You can still reuse app.config if you insist on doing so, but you need to come up with your own way to parse it.
Here is the necesary steps for this workaround:
In the Setup Project, add Project Output in the Application Folder and choose Content Files instead of Primary output. You can verify that app.config is the output by invoking context menu and choosing Outputs for the Content Files from ... item.
After you've done this, you should have 2 outputs from the Custom Installer class library project (1 for Primary output and 1 for the Content Files).
Here is an example custom installer action that will launch whatever I have in my appSettings key called launch along with my replacement ConfigurationManager implementation: