title: WiX/MSI dynamically add CopyFile elements
body: <p>I am a noob in Windows programming, but I have to create a tricky MSI installer that installs a plugin via WiX toolset.
  The installer should detect upon running all installed versions of specific software and their plug-ins directories via Windows Registry API. After that it should show all of them on a separate page (dialog) with appropriare checkboxes. A user should choose what versions they want the plugin install into.</p>
  
  <p>I've created a custom action (in C++ and put it into a DLL that is in the MSI database) that interacts registry API then loops over the results and adds temporary records to the database tables: </p>
  
  <ul>
  <li>adds path properites to persist the plugin paths;</li>
  <li>adds records to the CheckBox table;</li>
  <li>adds properties for them to hold their states;</li>
  <li>adds conditions for them than checks their property states and enables/disables them;</li>
  <li>adds events to reset path properties according to the state properies.</li>
  </ul>
  
  <p>It runs after AppSearch</p>
  
  <pre><code>&lt;InstallUISequence&gt;
     &lt;Custom Action="PopulateVersions" After="AppSearch"&gt;Not Installed&lt;/Custom&gt;
  &lt;/InstallUISequence&gt;
  </code></pre>
  
  <p>Then clicking Next button (I know that it's a wrong place to do such things) performs the custom action that filters off active property paths takes the first of them and performs the SetTargetPath action (it works fine). For the rest of them the action inserts appropriate temporary records into:</p>
  
  <ul>
  <li>the DuplicateFile table, where DestFolder is the property name;</li>
  <li>the Component table, copying all field values from the original component, setting the Component_Parent field value to the original;</li>
  <li>the Directory table. One record per path property, Direcory_Parent is TARGETDIR;</li>
  </ul>
  
  <p>It installed the plugin only to the first property path refers to (which was passed to the SetTargetPath action).</p>
  
  <p>Fine... I added a few CopyFile elements that refer to my custom properties (I declared a few properies to prevent MSI build error due to unknown properties) to the WiX markup just for testing:</p>
  
  <pre><code>    &lt;Property Id="PathProperty0" Value="{}"/&gt;
      &lt;Property Id="PathProperty1" Value="{}"/&gt;
      &lt;Property Id="PathProperty2" Value="{}"/&gt;
  
      &lt;Directory Id="TARGETDIR" Name="SourceDir"&gt;
        &lt;Directory Id="ProgramFiles64Folder"&gt;
          &lt;Directory Id="INSTALLLOCATION" Name="MyPluginDir"&gt;
            &lt;Component Id="PluginExt" Guid="C112184A-307C-5E15-994F-0DFDA9DD427E"&gt;
              &lt;File Id="MyPlugin" Name="MyPlugin.dll" Source="MyPlugin.dll" Vital="yes" /&gt;
              &lt;CopyFile Id="MyPlugin_Copy1" FileId="MyPlugin" DestinationProperty="PathProperty1"/&gt;
              &lt;CopyFile Id="MyPlugin_Copy2" FileId="MyPlugin" DestinationProperty="PathProperty2"/&gt;
            &lt;/Component&gt;
          &lt;/Directory&gt;
        &lt;/Directory&gt;
      &lt;/Directory&gt;
  </code></pre>
  
  <p>Now the ProgressDialog is saying that "{}" is invalid path, but all of the properties were set to valid paths (I've checked this in debug)! <strong>Seems like it forgets or ignores all  temporary database changes/property changes after showing elevating UAC prompt that asks for access to the same MSI file.</strong> The prompt is raised after clicking the Install button (with a shield icon). Probably it reads the database again and does not find any changes as they were in memory or cache, I don't know.</p>
  
  <p>What am I doing wrong or how to make that installer properly? IMHO my implementation is overcomplicated. I do need your assistance.</p>