WIX: Change configuration files even if features set is not changed - wix

I have a wix installer which installs several web sites. Each website is a feature. There is a custom dialog which allows to enter database connection strings. Each feature contains a component which changes configuration file using the data entered in a dialog. It works fine.
Then I run the same installer and select the option Change. I do not change features set but I change connection strings. Then my changes are not applied to configuration files.
I understand why it happens, no feature change = no component run.
But is there a way to always change config files during change operation even if features list doesn't change?

Related

Where does a console application REALLY store its settings

I've created a console app (VS2015, target framework 4.5.2) and I have used My Project/Settings to create application level settings. All the documentation and answers here on stackoverflow.com tell me (and this is the way I've always understood it to work) that the app.config file are where these things are stored and I can indeed see these settings in app.config and I can open settings.vb to look at the properties and their default values.
So far so good, when I compiled this and chucked ONLY the executable on a different machine, as expected it worked. I am assuming this is because settings.vb is compiled into the app.
But I am left with an application for which I can't change the settings. Where do I now put the app.config so that I can indeed change the settings in the XML and have my application use those settings instead of the default ones next time? I hope I don't have to build an installer or do a publish because to me that completely defeats the purpose of console applications.
By default the settings in app.config are also embedded into your code (just for those situations like what you describe... where you just have the EXE without any *.config file). You can change this behavior by changing the GenerateDefaultValueInCode for each setting.
There are two sections to the file... the application section has the read-only setting for the entire app. The user section has the starting default values of the settings that the user can change.
So, just to review:
app.config = the design-time version of all the settings (it gets
renamed and copied to bin)
YourApplication.exe.config = the run-time
version of the all of the settings
%LOCALAPPDATA%\App\Version\user.config = just the user portion of the
settings after they've made changes

Where to place the program.exe.config file when creating a WIX installer

I'm creating a WIX installer for a C# application.
In the application I use System.Configuration.ConfigurationManager.AppSettings[Setting1] to get settings.
My question is, where must I place the program.exe.config file on the machine in order for it to work?
I can't place it with the program in ProgramFiles directory, since those files are read-only.
I tried:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
config.AppSettings.Settings[Config1].Value = "Value1";
config.Save();
Unfortunately I don't know where it's looking.
Thanks your replies, Trevy
It should be in the same folder of the program.exe. Use wix to copy both program.exe and program.exe.config to the required folder.
If you need to edit the configuration file during the installation you will need to do it using a custom action in wix. Make sure you pass the file path to the custom action and write the code to read the configurations in that file and edit.
The problem isn't that the files there are readonly - the problem is that you are trying to update files in the Program Files folder with your config.Save, and you can't do that if you are a limited user, and you are always limited (even if you are admin) unless you elevate. The short answer is that:
If your app routinely updates files in restricted areas then it probably needs elevation, so give it an elevation manifest.
If however you require you app to be used by limited users and allow them to update that config file then don't install to Program Files. Choose User Appdata folder, for example. Windows is probably using your config file during program startup, so you can't separate it from the exe.
When I was creating an installer for my app, I found I couldn’t save my settings.
The reason is because the Program Files repository, from a practical point of view, is read-only (Applications should never run with elevated permissions). When installing a program, the only time we modify the MyApp.exe.config file is at installation/upgrade/repair time.
The config file has many sections. One of them is userSettings. This is where we store any data we need to modify during the lifetime of the application. When run for the first time, Windows creates a hidden file in the user’s AppData folder. That is why we can save user settings, even though the config file is in the same directory as the MyApp.exe
So the answer is, if we run into permission errors when trying to save our settings it means we are writing our settings to the wrong section of the config file. We need to place it in the userSettings section and nowhere else.
For convenience, Visual Studios has a settings editor (the settings tab of the properties page). It allows you to create strongly typed user and application settings. The generated class lets you save user settings, but not application settings for the above reasons.

WIX: Saving off user data files during major upgrade

My application runs as a Windows service. During normal execution, some data files are generated in a "data" directory that I create with my WIX install. During an upgrade, I would like to move/migrate those files to the same data dir in the upgraded installation. However, I am running into issues. I am using the "MajorUpgrade" tag as follows:
I tried scheduling later in the process(afterInstallFinalize), but that runs into issues with the service having locks on files during the upgrade. I have combed Stack Overflow and google, and it seems that no one else is describing my scenario. Others have default *.ini files, that the user can potentially edit. However, in my case, it should always be safe to migrate the files, as there are no defaults. They are simply data files that need to be migrated.
I thought I could possibly do this via a custom action, but was not sure how to do it.
Any suggestions would be very much appreciated.
Edit: Apparently using "afterInstallFinalize" works fine for me, i.e. data files are migrated, as long as the user does not change the path during upgrade. If I change the path during upgrade, I get warnings about files being locked, and asking to stop the app using the files. However, it ends up not migrating the files in that case.
Ultimately, I solved my own issue by simply overriding the default dialog behavior, and changing the flow such that on upgrade, I skip over the "InstallDirDlg".

How do web apps do automated updates without breaking config settings?

Let's say I have a mediawiki installation. I mess about with it, add little hacks to make the wikipedia logo change into tigger, and bounce up and down.
Now it's time to update to the newest version, so I download it and run the update script. Let say it changed several variables, like $wglogo, the image path to the logo. How does the update script ensure that the logo image path changes (according to the specs of the new version, in this figurative example), while keeping tigger bouncing on the main page?
That is: How do new versions integrate changes to the configuration file without overwriting the user-defined changes in the config file-to-be-overwrit?
Typically we try not to change config files on update. Almost all new configuration settings are optional and thus are not added to the config files upon upgrade. In the rare case where we have to change an existing setting, make the smallest change required to the config file so as not to affect any other things.
Testing is very important. Gather as many real client configurations as possible and create unit tests for the auto-updater to validate that the configs don't gets screwed upon upgrade.

Add a shortcut to Startup folder with parameters in Adobe AIR

I am trying to include a link to my application in the Startup folder with a parameter passed to the program.
I think it would work if I created the shortcut locally and then added it to my source. After that I could copy it to the Startup folder on first run.
File.userDirectory.resolvePath("Start Menu\\Programs\\Startup\\startup.lnk");
However, I am trying to get this to occur during install. I see there is are some settings related to the installation in app.xml, but nothing that lets me install it to two folders, or use a parameter.
<!-- The subpath of the standard default installation location to use. Optional. -->
<!-- <installFolder></installFolder> -->
<!-- The subpath of the Windows Start/Programs menu to use. Optional. -->
<!-- <programMenuFolder></programMenuFolder> -->
I'm new to Air, but also haven't found any way to customize the install process. It looks like you're limited to your application code. (Updating appears more flexible.)
From your example, it looks like you want your app' to run with a parameter constant each time Windows starts. So you're probably already aware you can set:
NativeApplication.nativeApplication.startAtLogin=true
when your app' first runs. Could you combine this with your parameter in a settings file in the application or user directory and accomplish what you need?