简体   繁体   中英

Hot ti Install File just in the first time with WIX

I have a component

<Component Id="ProductComponent" Guid="7935315f-4242-4c7a-a02c-6fd256805356">
    <CreateFolder/>
      <File
          Id="propFile"
          Name="aaa.properties"
          DiskId="1"
          Source="$(var.Project.TargetDir)"
          Vital="yes"
          KeyPath="yes" ></File>
      <?endif?>

</Component>

I want to copy the file just on install, not upgrade. But I can't find how to do it.

Any idea?

Have you tried using Condition element. I think you can provide a Condition inside Component element to check whether product is already installed or not. If not installed, then create file.

<Component Id="ProductComponent" Guid="7935315f-4242-4c7a-a02c-6fd256805356">
  <Condition> NOT Installed </Condition>
  <CreateFolder/>
  <File
       Id="propFile"
       Name="aaa.properties"
       DiskId="1"
       Source="$(var.Project.TargetDir)"
       Vital="yes"
       KeyPath="yes" ></File>
</Component>

This is a weak spot of MSI (which WiX uses).

MSI installs a file User modifies the file MSI goes to install the file. Should it:

a) overwrite and lose user data

b) not overwrite and lose new applciation data

c) merge --- MSI doesn't support this.

If the user data is only one or few attributes there are tricks with custom actions to harvest the user data and reapply it but this is very tricky stuff.

IMO, the best way to approach this is never keep user data in a file installed by the installer. Take app.config appSettings element as an example. It was an atttribute that allows you to extend the file with another file that overrides the settings in the first file. Using this pattern the installer can lay down the app config and the application can create the override file and everything just works because MSI doesn't have to deal with the problem at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM