I have a program that I am going to deploy via a Windows installer. The program outputs files to a location specified in a app.config file.
Is it possible to change the value of the config file to the path selected during the install?
So the process would be as follows.
- User runs windows installer
- User selects path to install program
- Output variable in app.config changed to location of install
- User can then edit the config file to change output variable if they wish to change the output path.
Update: Ok so now I know how to create a custom install process as per this link:
Configure App.config Application Settings During MSI Install
This is fine if you want to just use the standard set of controls but I would like a file chooser for them to be able to choose the output path, how can I do this?
Ok I figured out what I needed to do… Heres the answer…
Add an installer class to the project you want to install as per instructions in the link.
Then override the install method in that class as follows to read the path that that user inputs as install directory..
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string targetDirectory = Context.Parameters["targetdir"];
string exePath = string.Format("{0}BarcodeScanner.exe", targetDirectory);
Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
config.AppSettings.Settings["ILPrintExportPath"].Value = targetDirectory;
config.Save();
}
Then follow the other stages in the above link 🙂
As Joe said I will have to either ensure the users run the app as an administrator or install outside the program files directory so its not a perfect solution but it does what I need it to do.
See this article Configure App.config Application Settings During MSI Install which shows how to do this using a C# custom action which uses the standard .Net
ConfigurationManagerclass to open and update the app.config file.