I want to keep a config file when the msi installer does a major upgrade. For the config file, I make a change when installing. The code is as follows:
<Component Id="MODIFYCONFIG" Guid="6A1D7762-B707-4084-A01F-6F936CC159CE" Win64="yes">
<File Id="Application.config" Name="Application.config" Vital="yes" KeyPath="yes" Source="Resource\Application.config"></File>
<util:XmlFile Id="SetValueIP" Action="setValue" Permanent="yes" File="[#Application.config]"
ElementPath="/configuration/applicationSettings/Application.Properties.Settings/setting[\[]@name='IpAddress'[\]]/value" Value="[IPADDRESS]" Sequence="1"/>
<util:XmlFile Id="SetValuePort" Action="setValue" Permanent="yes" File="[#Application.config]"
ElementPath="/configuration/applicationSettings/Application.Properties.Settings/setting[\[]@name='IpPort'[\]]/value" Value="[PORT]" Sequence="2"/>
<Condition>Not Installed</Condition>
</Component>
<Component Id="KEEPCONFIG" Guid="F7F173AA-C2FD-4017-BFBC-B81852A671E7" Win64="yes">
<RemoveFile Id="ApplicationConfig" Name="Application.config" On="uninstall"/>
<Condition>(REMOVE=ALL) AND (NOT UPGRADINGPRODUCTCODE)</Condition>
</Component>
But when a major upgrade occurs the file is not preserved. How can I preserve the modified file?
This solved it for me... config file is preserved with minor/major upgrade, and completely removed on uninstall.
Ref: http://blogs.msdn.com/b/astebner/archive/2008/10/19/9006538.aspx
EDIT: Summarized info from the linked page...
It took me a while, but here is how I solved it myself. It's probably a variation of caveman_dick's third option.
1) Add new action into UISequence to back up your current config file. You can do it with the magic of custom action and ComponentSearch to actually locate the file.
2) Restore the file later in ExecuteSequence.
and here is quick CustomAction.cs I wrote:
to actually define sequences:
haven't tested it thoroughly, but seems to do the job for now. Caveat: Temp folder might change?!
Alternatively there is this one that I found from Internet, but haven't tested it.
There is another option, but it may not be applicable to your scenario - it all depends on who is initially running your installer...
If your app is downloaded over the web for example, then we usually go with caveman_dick's remember property pattern.
However, we have a couple of suites of products that are always installed by our own installation staff who visit a clients site. In this instance, simply do not include the config file in the installer at all!
Put simply - if the installer doesn't know about a file, then it won't uninstall it!
In this case you have the option of your installation team creating and configuring the config file, or your app creating it when it doesn't exist, and asking the user for the values.
As stated this won't be an option in some scenarios, but it works fine for ours.
You have 3 options when upgrading:
The best option is the remember me property as this has the least problems.
Add
Schedule="afterInstallExecuteAgain"
in the MajorUpgradeIt work for me