[英]Wix Conditionally Install Component if Registry Key Exists
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'." 到目前为止,我有以下脚本,但是出现错误“系统找不到文件'[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>
Based on my reading of the Wix Schema documentation, your problem is that you have the CopyFile element nested under a File element. 根据我对Wix Schema文档的阅读,您的问题是您将CopyFile元素嵌套在File元素下。 Ditch the File element and just have the CopyFile sit under the Component: 抛弃File元素,然后将CopyFile放在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. Wix嵌套在文件下的方式是在构建过程中在系统上查找文件-而不是设置要在安装时运行的复制命令。
MYTESTDIR
is a windows installer property which will get its value on the target system when the package is being installed . MYTESTDIR
是Windows安装程序的属性, 在安装软件包时将在目标系统上获取其值。
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 . 但是,您试图在Source
属性中使用此属性,该属性用于指向正在构建安装程序包的系统上的文件。
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. 在评估Source
属性时,Windows安装程序属性甚至不存在,因此Source
绝对不能支持这种使用。
Bryan's answer is the correct solution for what you're trying to do here. Bryan的答案是您在此尝试做的正确解决方案。 Using CopyFile
under a File
element is not illegal, but it is intended for copying files which you also install. 在File
元素下使用CopyFile
不是非法的,但是它用于复制您也安装的文件。 In this case, you want to copy a file which is already on the target system, so the File
element is not appropriate. 在这种情况下,您要复制目标系统上已经存在的文件,因此File
元素不合适。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.