Copy if not exist in WiX
Asked Answered
T

2

9

I have a config file, myapp.exe.config, that I want to install only if it does not already exist. That is, I don't want to overwrite any existing config file. How can this be done in WiX?

(Ultimately I will have to do something more sophisticated with settings, having defaults and overrides and so on. But in the meantime I am just looking for a short-term fix.)

Tasia answered 16/12, 2009 at 3:16 Comment(0)
T
13

What you describe is the default behavior if the file is the keypath of a component. For example, the following component will not be installed if foo.config already exists (or in the case of a versioned file, if a file with a equal or higher version number already exists):

<Component Id="foo.config">
   <File Source="foo.config"/>
</Component>

Note that if you have multiple files in your component, then only one can be the keypath. You can control this by setting the KeyPath attribute of the file to yes. But the recommended strategy is to have only one file per component, in which case the file automatically becomes the component keypath.

edit: note that this default behavior can be overridden with the REINSTALLMODE property. You may want to open your MSI with orca and see if this property is being set in the property table.

Tucci answered 16/12, 2009 at 20:19 Comment(1)
Thanks. It turns out that I have asked the wrong question. My installer has to be uninstalled before installing a new one. (The tutorial assures me that this is entirely normal for a minor upgrade.) The problem is that the config file is being deleted even if it has been modified by the user. I will have to investigate this.Tasia
D
8

You want to use NeverOverwrite and Permanent on the component...

<Component Id="foo.config.cmp" NeverOverwrite="yes" Permanent="yes" Guid="INSERT_GUID_HERE">
    <File Id="foo.config.file" KeyPath="yes" Source="foo.config"/>
</Component>

I use this on my config.json files that contain really long nasty connection strings to a web service. It should never be blanked out by any user action and linger behind after an uninstall.

http://wixtoolset.org/documentation/manual/v3/xsd/wix/component.html

Dearth answered 26/10, 2018 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.