tags:

views:

453

answers:

2

I have a component I need to install only if a registry key exists which means an application has been installed.

I need to assign the value of the registry key (it is a directory) to a property then use this property to copy files from.

I have the following script so far but get an error "The system cannot find the file '[MYTESTDIR]fileToCopy.dat'."

Any help would really be appreciated.

<Property Id="MYTESTDIR">
    <RegistrySearch Id="NetFramework20"
            Root="HKLM"
            Key="SOFTWARE\TEST\VALUE\1.00"
            Name="MyName"
            Type="directory" />
</Property>

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
        <Directory Id="TEST" Name="Test">       
            <Component Id="MyComponent" Guid="E5FF53DE-1739-42c4-BE37-60F810C9CD69">
              <Condition>MYTESTDIR</Condition>
              <File Id="fileToCopy.dat" Name="fileToCopy.dat" Source="[MYTESTDIR]fileToCopy.dat">
                  <CopyFile Id="fileToCopy.datCopy" DestinationProperty="WEBSERVICEBINFOLDER" />
              </File>

        </Directory>            
    </Directory>
</Directory>

<Feature Id="MyFeature" Title="MyFeature" Level="1">
    <ComponentRef Id="MyComponent" />
</Feature>
+4  A: 

Based on my reading of the Wix Schema documentation, your problem is that you have the CopyFile element nested under a File element. Ditch the File element and just have the CopyFile sit under the Component:

<Component Id="MyComponent" Guid="E5FF53DE-1739-42c4-BE37-60F810C9CD69"> 
  <Condition>MYTESTDIR</Condition> 
  <CopyFile Id="fileToCopy.datCopy" SourceName="[MYTESTDIR]fileToCopy.dat" DestinationProperty="WEBSERVICEBINFOLDER" />
</Component>

The way you had it, nested under the File, Wix was looking for the file on your system during the build - rather than setting up a copy command to be run at install time.

Bryan Batchelder
+1  A: 

MYTESTDIR is a windows installer property which will get its value on the target system when the package is being installed.

However, you are trying to use this property in a Source attribute, which is used to point to files on the system where the setup package is being build.

Obviously that is not going to work. Windows installer properties don't even exist while the Source attribute is being evaluated, so Source can definitely not support such use.

Bryan's answer is the correct solution for what you're trying to do here. Using CopyFile under a File element is not illegal, but it is intended for copying files which you also install. In this case, you want to copy a file which is already on the target system, so the File element is not appropriate.

Wim Coenen