Force update for unversioned files

Nov 30, 2016 at 11:05 AM
Hello,
What's the best way to force the update of unversioned files?
I have a set of XML files that have to be updated with any product upgrade, even if the user modified some of them after the previous installation/upgrade. The MSI file versioning rules (https://msdn.microsoft.com/en-us/library/aa368599(v=vs.85).aspx) prevent the update of the modified files in such cases. As far as I understand, using 'Companion Files' (i.e. linking those unversioned XML files to the versions of the exes/dlls) would be the way to go, but I can't find the support for that feature in Wix#.
Any advice please?
Thanks.
Coordinator
Dec 2, 2016 at 2:12 AM
As with many other non primary attributes CompanionFile can be set via AttributeDefinition:
new File(@"Files\Docs\Manual.txt")
{
    AttributesDefinition = "CompanionFile=<whatever_value_you_need>"
}),
Though as for me, I wouldn't go this way. To be honest I even found the whole concept of something being installed, then overwritten by user, then replaced by the upgrade is questionable. It seems like a better separation between default and user specific settings is what your solution is lacking. MSI is a deployment solution so it only should be concerned about the delivery of the files but not about making any decisions regarding their content fate.

Anyway, if I really need to implement your requirement I would rather use something more manageable than MSI/WiX:
var project = 
    new Project("MyProduct",
        new Dir(@"%ProgramFiles%\My Company\My Product",
            new File(@"Files\Bin\MyApp.exe"),
            new File(@"Files\Bin\MyApp.exe.config.default"),
           ...
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
{
    if (e.IsInstalling)
    {
        // do any comprehensive analysis here
        string defaultConfig = Path.Combine(e.e.InstallDir, "MyApp.exe.config.default");
        string userConfig = Path.Combine(e.e.InstallDir, "MyApp.exe.config");
        File.Copy(defaultConfig, userConfig, true);
    }
}
This way there is a clear separation of concerns and you can also decide if you want to preserve some of the user settings.
You can even abort the settings overwriting completely (e.g. during repair/reinstall).
Marked as answer by Menshchikov on 12/2/2016 at 1:48 AM